Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions sentry_sdk/integrations/django/asgi.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""
Instrumentation for Django 3.0

Since this file contains `async def` it is conditionally imported in
`sentry_sdk.integrations.django` (depending on the existence of
`django.core.handlers.asgi`.
Since this file imports `django.core.handlers.asgi` (Django >= 3)
it is conditionally imported in `sentry_sdk.integrations.django`.
"""

import asyncio
Expand Down
16 changes: 6 additions & 10 deletions sentry_sdk/integrations/django/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import functools
import sys
from typing import TYPE_CHECKING

import sentry_sdk
Expand All @@ -10,15 +11,15 @@
from typing import Any


try:
if sys.version_info >= (3, 14):
from inspect import iscoroutinefunction
else:
from asyncio import iscoroutinefunction
except ImportError:
iscoroutinefunction = None # type: ignore


try:
from sentry_sdk.integrations.django.asgi import wrap_async_view
except (ImportError, SyntaxError):
except ImportError: # Django < 3.0
wrap_async_view = None # type: ignore


Expand Down Expand Up @@ -63,12 +64,7 @@ def sentry_patched_make_view_atomic(

integration = sentry_sdk.get_client().get_integration(DjangoIntegration)
if integration is not None:
is_async_view = (
iscoroutinefunction is not None
and wrap_async_view is not None
and iscoroutinefunction(callback)
)
if is_async_view:
if wrap_async_view is not None and iscoroutinefunction(callback):
sentry_wrapped_callback = wrap_async_view(callback)
else:
sentry_wrapped_callback = _wrap_sync_view(callback)
Expand Down