Skip to content

Commit ad28065

Browse files
authored
fix: Do not disable contextvars if gevent successfully patched them (getsentry#695)
* fix: Do not disable contextvars if gevent successfully patched them * fix: Fix tests
1 parent c0d88a9 commit ad28065

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

sentry_sdk/utils.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -722,12 +722,15 @@ def strip_string(value, max_length=None):
722722
return value
723723

724724

725-
def _is_threading_local_monkey_patched():
725+
def _is_contextvars_broken():
726726
# type: () -> bool
727727
try:
728728
from gevent.monkey import is_object_patched # type: ignore
729729

730730
if is_object_patched("threading", "local"):
731+
if is_object_patched("contextvars", "ContextVar"):
732+
return False
733+
731734
return True
732735
except ImportError:
733736
pass
@@ -752,7 +755,7 @@ def _get_contextvars():
752755
753756
https://github.com/gevent/gevent/issues/1407
754757
"""
755-
if not _is_threading_local_monkey_patched():
758+
if not _is_contextvars_broken():
756759
# aiocontextvars is a PyPI package that ensures that the contextvars
757760
# backport (also a PyPI package) works with asyncio under Python 3.6
758761
#

tests/utils/test_contextvars.py

-11
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,6 @@
33
import time
44

55

6-
from sentry_sdk.utils import _is_threading_local_monkey_patched
7-
8-
9-
@pytest.mark.forked
10-
def test_thread_local_is_patched(maybe_monkeypatched_threading):
11-
if maybe_monkeypatched_threading is None:
12-
assert not _is_threading_local_monkey_patched()
13-
else:
14-
assert _is_threading_local_monkey_patched()
15-
16-
176
@pytest.mark.forked
187
def test_leaks(maybe_monkeypatched_threading):
198
import threading

0 commit comments

Comments
 (0)