Skip to content

Commit

Permalink
- integrations/django/middleware.py: do not pass get_response to sup…
Browse files Browse the repository at this point in the history
…er().__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 <daniel.szoke@sentry.io>
  • Loading branch information
cameron-simpson and szokeasaurusrex committed Jul 15, 2024
1 parent 855c15f commit b24138b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions sentry_sdk/integrations/django/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from functools import wraps
from typing import Any

from django import VERSION as DJANGO_VERSION

Expand All @@ -29,10 +30,13 @@
"import_string_should_wrap_middleware"
)

if DJANGO_VERSION < (3, 1):
_asgi_middleware_mixin_factory = lambda _: object
else:
DJANGO_SUPPORTS_ASYNC_MIDDLEWARE = DJANGO_VERSION >= (3, 1)
if DJANGO_SUPPORTS_ASYNC_MIDDLEWARE:
from .asgi import _asgi_middleware_mixin_factory
else:

def _asgi_middleware_mixin_factory(_) -> Any:
return object


def patch_django_middlewares():
Expand Down Expand Up @@ -122,7 +126,9 @@ def sentry_wrapped_method(*args, **kwargs):
class SentryWrappingMiddleware(
_asgi_middleware_mixin_factory(_check_middleware_span) # type: ignore
):
async_capable = getattr(middleware, "async_capable", False)
async_capable = DJANGO_SUPPORTS_ASYNC_MIDDLEWARE and getattr(
middleware, "async_capable", False
)

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

0 comments on commit b24138b

Please sign in to comment.