Skip to content

fix(sqlalchemy): avoid IndexError in _operation_name for comment/whitespace-only statements - #4943

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

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

Conversation

@Atishyy27

Copy link
Copy Markdown

Same class as #4934, in the SQLAlchemy instrumentation's _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 so such a statement falls back to the db name / vendor instead of crashing.

Type of change: Bug fix (non-breaking)

How Has This Been Tested? Added test_operation_name_comment_or_whitespace_only (unit test on _operation_name); existing tests still pass. Verified locally.

Does This PR Require a Core Repo Change? No.

…espace-only statements

A statement that is truthy but has no tokens after leading-comment or whitespace
stripping made .split()[0] raise IndexError in _operation_name. Guard it so such a
statement falls back to the db name / vendor instead of crashing. 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