8000 fix(tracing): Use `hasattr` for `_ctx_token` (#4541) · getsentry/sentry-python@cd422af · GitHub
[go: up one dir, main page]

Skip to content

Commit cd422af

Browse files
fix(tracing): Use hasattr for _ctx_token (#4541)
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. <!-- Describe your PR here --> --- Thank you for contributing to `sentry-python`! Please add tests to validate your changes, and lint your code using `tox -e linters`. Running the test suite on your PR might require maintainer approval.
1 parent 401a003 commit cd422af

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)
0