Skip to content

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

Open
Atishyy27 wants to merge 3 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 3 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.

Atishyy27 added a commit to Atishyy27/opentelemetry-python-contrib that referenced this pull request Aug 10, 2026
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
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Aug 14, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on maintainers · refreshed 2026-08-21 09:56 UTC

Merge when ready.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@github-project-automation github-project-automation Bot moved this to Reviewed PRs that need fixes in Python PR digest Aug 17, 2026
Atishyy27 added a commit to Atishyy27/opentelemetry-python-contrib that referenced this pull request Aug 17, 2026
…only statements

Per xrmx's review on open-telemetry#4942: the regression test only checked that a
comment-only or whitespace-only statement produces spans without crashing,
not what those spans are actually named. Asserts the fallback ('postgresql',
the db vendor, per this test's MockConnection fixture) instead of just span
count.
…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>
…only statements

Per xrmx's review on open-telemetry#4942: the regression test only checked that a
comment-only or whitespace-only statement produces spans without crashing,
not what those spans are actually named. Asserts the fallback ('postgresql',
the db vendor, per this test's MockConnection fixture) instead of just span
count.
@Atishyy27
Atishyy27 force-pushed the fix/psycopg2-operation-name-empty-tokens branch from f6e0667 to 13471a3 Compare August 20, 2026 23:57
@github-project-automation github-project-automation Bot moved this from Reviewed PRs that need fixes to Approved PRs in Python PR digest Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

2 participants