From 51494c7ad6836fc524780af65fba33aeca25ec5f Mon Sep 17 00:00:00 2001 From: Austin Morton Date: Fri, 2 Feb 2024 15:49:44 -0500 Subject: [PATCH] Guard against sentry initialization mid sqlalchemy cursor --- sentry_sdk/integrations/sqlalchemy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/sqlalchemy.py b/sentry_sdk/integrations/sqlalchemy.py index eb665b148a..579723ff08 100644 --- a/sentry_sdk/integrations/sqlalchemy.py +++ b/sentry_sdk/integrations/sqlalchemy.py @@ -95,7 +95,7 @@ def _after_cursor_execute(conn, cursor, statement, parameters, context, *args): context._sentry_sql_span_manager = None ctx_mgr.__exit__(None, None, None) - span = context._sentry_sql_span + span = getattr(context, "_sentry_sql_span", None) # type: Optional[Span] if span is not None: with capture_internal_exceptions(): add_query_source(hub, span)