From 4b5cfba1209f9d4b71f9e7792ef44699d09124bb Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Fri, 7 Jun 2024 12:37:22 +0200 Subject: [PATCH] Since Django 3 the channels handler is deprecated --- sentry_sdk/integrations/django/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/integrations/django/__init__.py b/sentry_sdk/integrations/django/__init__.py index 3a6a075c70..6389779c7f 100644 --- a/sentry_sdk/integrations/django/__init__.py +++ b/sentry_sdk/integrations/django/__init__.py @@ -321,10 +321,14 @@ def sentry_patched_drf_initial(self, request, *args, **kwargs): def _patch_channels(): # type: () -> None try: + # Django < 3.0 from channels.http import AsgiHandler # type: ignore except ImportError: - return - + try: + # DJango 3.0+ + from django.core.handlers.asgi import ASGIHandler as AsgiHandler + except ImportError: + return if not HAS_REAL_CONTEXTVARS: # We better have contextvars or we're going to leak state between # requests.