fix(psycopg): avoid IndexError in get_operation_name for comment/whitespace-only statements - #4936
Open
Atishyy27 wants to merge 2 commits into
Open
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Same class as #4934, in the psycopg instrumentation's
get_operation_nameoverride: a comment-only / whitespace-onlyComposedstatement is truthy but has no tokens left after leading-comment stripping, so.split()[0]raisesIndexError. 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-onlyComposedno longer raises); the existingtest_instrument_connection_composed_querystill passes. Verified locally.Does This PR Require a Core Repo Change? No.