Skip to content

Commit 02cef85

Browse files
fix(tracing): Use hasattr for _ctx_token
We currently use an `if self._ctx_token` check to determine if a span has a `_ctx_token`. However, this check is incorrect, since `_ctx_token` is only sometimes set. Furthermore, when `_ctx_token` is set, we should always have a `_ctx_token`. Therefore, using `hasattr` is what we want.
1 parent b07438d commit 02cef85

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

sentry_sdk/tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def activate(self) -> None:
248248
self._ctx_token = context.attach(ctx)
249249

250250
def deactivate(self) -> None:
251-
if self._ctx_token:
251+
if hasattr(self, "_ctx_token"):
252252
context.detach(self._ctx_token)
253253
del self._ctx_token
254254

0 commit comments

Comments
 (0)