Skip to content

Guard against sentry initialization mid sqlalchemy cursor#2702

Merged
sentrivana merged 1 commit intogetsentry:masterfrom
apmorton:patch-1
Feb 5, 2024
Merged

Guard against sentry initialization mid sqlalchemy cursor#2702
sentrivana merged 1 commit intogetsentry:masterfrom
apmorton:patch-1

Conversation

@apmorton
Copy link
Copy Markdown
Contributor

@apmorton apmorton commented Feb 2, 2024

In an application that is executing sqlalchemy cursors on a thread concurrently with another thread calling sentry_sdk.init it is possible for _after_cursor_execute to be called on a cursor that never had _before_cursor_execute called.

  File "site-packages/sentry_sdk/integrations/sqlalchemy.py", line 98, in _after_cursor_execute
    span = context._sentry_sql_span
           ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'PGExecutionContext_psycopg2' object has no attribute '_sentry_sql_span'

Copy link
Copy Markdown
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @apmorton!

@sentrivana sentrivana enabled auto-merge (squash) February 5, 2024 14:51
@sentrivana sentrivana merged commit 4afb955 into getsentry:master Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants