Skip to content

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

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

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

Conversation

@Atishyy27

Copy link
Copy Markdown

Same class as #4934, in the psycopg instrumentation's get_operation_name override: a comment-only / whitespace-only Composed statement is truthy but has no tokens left after leading-comment stripping, so .split()[0] raises IndexError. This guards it the same way the dbapi base does (tokens[0] if tokens else "").

Follow-up to #4934, kept as a separate PR per the single-logical-change discussion there.

Type of change: Bug fix (non-breaking)

How Has This Been Tested?
Added test_instrument_connection_comment_only_composed_query (a comment-only Composed no longer raises); the existing test_instrument_connection_composed_query still passes. Verified locally.

Does This PR Require a Core Repo Change? No.

…espace-only Composed statements

A Composed statement that is truthy but has no tokens after leading-comment or
whitespace stripping made `.split()[0]` raise IndexError in the psycopg
instrumentation's get_operation_name override. Guard it the same way the dbapi
base does, returning an empty operation name instead. 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 8, 2026 19:41
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