Skip to content

Commit 16d05f4

Browse files
fix(django): SentryWrappingMiddleware.__init__ fails if super() is object
As described in issue getsentry#2461, the SentryWrappingMiddleware MRO is just object if Django < 3.1 (when async middleware became a thing), but the async_capable check inside the class only looks for the async_capable attribute inside the middleware class. This PR makes that check also conditional on Django >= 3.1. Otherwise the code calls super(.....).__init__(get_response) and for Django < 3.1 this only finds object.__init__, not the wrapped middleware __init__. --- Co-authored-by: Daniel Szoke <daniel.szoke@sentry.io>
1 parent 9df2b21 commit 16d05f4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

sentry_sdk/integrations/django/middleware.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
"import_string_should_wrap_middleware"
3131
)
3232

33-
if DJANGO_VERSION < (3, 1):
33+
DJANGO_SUPPORTS_ASYNC_MIDDLEWARE = DJANGO_VERSION >= (3, 1)
34+
35+
if not DJANGO_SUPPORTS_ASYNC_MIDDLEWARE:
3436
_asgi_middleware_mixin_factory = lambda _: object
3537
else:
3638
from .asgi import _asgi_middleware_mixin_factory
@@ -123,7 +125,9 @@ def sentry_wrapped_method(*args, **kwargs):
123125
class SentryWrappingMiddleware(
124126
_asgi_middleware_mixin_factory(_check_middleware_span) # type: ignore
125127
):
126-
async_capable = getattr(middleware, "async_capable", False)
128+
async_capable = DJANGO_SUPPORTS_ASYNC_MIDDLEWARE and getattr(
129+
middleware, "async_capable", False
130+
)
127131

128132
def __init__(self, get_response=None, *args, **kwargs):
129133
# type: (Optional[Callable[..., Any]], *Any, **Any) -> None

0 commit comments

Comments
 (0)