Skip to content

Commit 4046951

Browse files
ref(scope): Properly type Scope.root_span (#4273)
Currently, this property has type `Any`, but it can now be changed to `Optional[Span]` Depends on: - #4263
1 parent a45c4f1 commit 4046951

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

sentry_sdk/integrations/huey.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,13 @@ def _capture_exception(exc_info):
111111
# type: (ExcInfo) -> None
112112
scope = sentry_sdk.get_current_scope()
113113

114-
if exc_info[0] in HUEY_CONTROL_FLOW_EXCEPTIONS:
115-
scope.root_span.set_status(SPANSTATUS.ABORTED)
116-
return
114+
if scope.root_span is not None:
115+
if exc_info[0] in HUEY_CONTROL_FLOW_EXCEPTIONS:
116+
scope.root_span.set_status(SPANSTATUS.ABORTED)
117+
return
118+
119+
scope.root_span.set_status(SPANSTATUS.INTERNAL_ERROR)
117120

118-
scope.root_span.set_status(SPANSTATUS.INTERNAL_ERROR)
119121
event, hint = event_from_exception(
120122
exc_info,
121123
client_options=sentry_sdk.get_client().options,
@@ -136,8 +138,10 @@ def _sentry_execute(*args, **kwargs):
136138
exc_info = sys.exc_info()
137139
_capture_exception(exc_info)
138140
reraise(*exc_info)
139-
else:
140-
sentry_sdk.get_current_scope().root_span.set_status(SPANSTATUS.OK)
141+
142+
root_span = sentry_sdk.get_current_scope().root_span
143+
if root_span is not None:
144+
root_span.set_status(SPANSTATUS.OK)
141145

142146
return result
143147

sentry_sdk/scope.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,7 @@ def fingerprint(self, value):
692692

693693
@property
694694
def root_span(self):
695-
# type: () -> Any
696-
# would be type: () -> Optional[Span], see https://github.com/python/mypy/issues/3004
695+
# type: () -> Optional[Span]
697696
"""Return the root span in the scope, if any."""
698697

699698
# there is no span/transaction on the scope

0 commit comments

Comments
 (0)