diff --git a/sentry_sdk/integrations/huey.py b/sentry_sdk/integrations/huey.py index 720d38f8e2..1d1c498843 100644 --- a/sentry_sdk/integrations/huey.py +++ b/sentry_sdk/integrations/huey.py @@ -111,11 +111,13 @@ def _capture_exception(exc_info): # type: (ExcInfo) -> None scope = sentry_sdk.get_current_scope() - if exc_info[0] in HUEY_CONTROL_FLOW_EXCEPTIONS: - scope.root_span.set_status(SPANSTATUS.ABORTED) - return + if scope.root_span is not None: + if exc_info[0] in HUEY_CONTROL_FLOW_EXCEPTIONS: + scope.root_span.set_status(SPANSTATUS.ABORTED) + return + + scope.root_span.set_status(SPANSTATUS.INTERNAL_ERROR) - scope.root_span.set_status(SPANSTATUS.INTERNAL_ERROR) event, hint = event_from_exception( exc_info, client_options=sentry_sdk.get_client().options, @@ -136,8 +138,10 @@ def _sentry_execute(*args, **kwargs): exc_info = sys.exc_info() _capture_exception(exc_info) reraise(*exc_info) - else: - sentry_sdk.get_current_scope().root_span.set_status(SPANSTATUS.OK) + + root_span = sentry_sdk.get_current_scope().root_span + if root_span is not None: + root_span.set_status(SPANSTATUS.OK) return result diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 1f3162605f..5aca30d62d 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -692,8 +692,7 @@ def fingerprint(self, value): @property def root_span(self): - # type: () -> Any - # would be type: () -> Optional[Span], see https://github.com/python/mypy/issues/3004 + # type: () -> Optional[Span] """Return the root span in the scope, if any.""" # there is no span/transaction on the scope