Skip to content

Commit 815e930

Browse files
committed
Better checks and importing only once
1 parent 096579e commit 815e930

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

sentry_sdk/integrations/threading.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ def setup_once():
5050
# type: () -> None
5151
old_start = Thread.start
5252

53+
try:
54+
from django import VERSION as django_version # noqa: N811
55+
import channels # type: ignore[import-not-found]
56+
57+
channels_version = channels.__version__
58+
except ImportError:
59+
django_version = None
60+
channels_version = None
61+
5362
@wraps(old_start)
5463
def sentry_start(self, *a, **kw):
5564
# type: (Thread, *Any, **Any) -> Any
@@ -58,17 +67,8 @@ def sentry_start(self, *a, **kw):
5867
return old_start(self, *a, **kw)
5968

6069
if integration.propagate_scope:
61-
try:
62-
from django import VERSION as django_version # noqa: N811
63-
import channels # type: ignore[import-not-found]
64-
65-
channels_version = channels.__version__
66-
except ImportError:
67-
django_version = None
68-
channels_version = None
69-
7070
if (
71-
sys.version_info <= (3, 8)
71+
sys.version_info < (3, 9)
7272
and channels_version is not None
7373
and channels_version < "4.0.0"
7474
and django_version is not None

tests/integrations/django/asgi/test_asgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async def test_basic(sentry_init, capture_events, application):
3838

3939
events = capture_events()
4040

41-
if sys.version_info <= (3, 8):
41+
if sys.version_info < (3, 9):
4242
# We emit a UserWarning for channels 2.x and 3.x on Python 3.8 and older
4343
# because the async support was not really good back then and there is a known issue.
4444
# See the TreadingIntegration for details.

0 commit comments

Comments
 (0)