Skip to content

Commit b24138b

Browse files
- integrations/django/middleware.py: do not pass get_response to super().__init__
- SentryWrappingMiddleware: revert debugging hack, set new django_supports_async_middleware = DJANGO_VERSION >= (3, 1), use for both _asgi_middleware_mixin_factory and the async_capable flag inside SentryWrappingMiddleware - integrations/django/middleware.py: black autoformat - integrations/django/middleware.py: use all caps for capability variable - sentry_sdk/integrations/django/middleware.py: annotate stub _asgi_middleware_mixin_factory to match the .asgi typing Co-authored-by: Daniel Szoke <[email protected]>
1 parent 855c15f commit b24138b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

sentry_sdk/integrations/django/middleware.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
from functools import wraps
6+
from typing import Any
67

78
from django import VERSION as DJANGO_VERSION
89

@@ -29,10 +30,13 @@
2930
"import_string_should_wrap_middleware"
3031
)
3132

32-
if DJANGO_VERSION < (3, 1):
33-
_asgi_middleware_mixin_factory = lambda _: object
34-
else:
33+
DJANGO_SUPPORTS_ASYNC_MIDDLEWARE = DJANGO_VERSION >= (3, 1)
34+
if DJANGO_SUPPORTS_ASYNC_MIDDLEWARE:
3535
from .asgi import _asgi_middleware_mixin_factory
36+
else:
37+
38+
def _asgi_middleware_mixin_factory(_) -> Any:
39+
return object
3640

3741

3842
def patch_django_middlewares():
@@ -122,7 +126,9 @@ def sentry_wrapped_method(*args, **kwargs):
122126
class SentryWrappingMiddleware(
123127
_asgi_middleware_mixin_factory(_check_middleware_span) # type: ignore
124128
):
125-
async_capable = getattr(middleware, "async_capable", False)
129+
async_capable = DJANGO_SUPPORTS_ASYNC_MIDDLEWARE and getattr(
130+
middleware, "async_capable", False
131+
)
126132

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

0 commit comments

Comments
 (0)