Skip to content

fix(psycopg2): avoid IndexError in get_operation_name for comment/whitespace-only statements - #4942

Open
Atishyy27 wants to merge 2 commits into
open-telemetry:mainfrom
Atishyy27:fix/psycopg2-operation-name-empty-tokens
Open

fix(psycopg2): avoid IndexError in get_operation_name for comment/whitespace-only statements#4942
Atishyy27 wants to merge 2 commits into
open-telemetry:mainfrom
Atishyy27:fix/psycopg2-operation-name-empty-tokens

Conversation

@Atishyy27

Copy link
Copy Markdown

Same class as #4934, in the psycopg2 instrumentation's get_operation_name: a comment-only / whitespace-only statement is truthy but has no tokens after leading-comment stripping, so .split()[0] raises IndexError. Guards it like the dbapi base does. Extends the empty-string handling from #2643 to this case.

Type of change: Bug fix (non-breaking)

How Has This Been Tested? Added test_span_name_comment_or_whitespace_only (comment-only + whitespace-only statements no longer raise); existing tests still pass. Verified locally.

Does This PR Require a Core Repo Change? No.

…tespace-only statements

A statement that is truthy but has no tokens after leading-comment or whitespace
stripping made .split()[0] raise IndexError in the psycopg2 instrumentation's
get_operation_name override. Guard it like the dbapi base does. Adds a regression
test. Follow-up to open-telemetry#4934.

Signed-off-by: Atishyy27 <142108881+Atishyy27@users.noreply.github.com>
Signed-off-by: Atishyy27 <142108881+Atishyy27@users.noreply.github.com>
@Atishyy27
Atishyy27 requested a review from a team as a code owner August 10, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant