Skip to content

Do not raise error when channels is not installed #3203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2024
Merged
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
8 changes: 2 additions & 6 deletions sentry_sdk/integrations/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,10 @@ 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:
try:
# DJango 3.0+
from django.core.handlers.asgi import ASGIHandler as AsgiHandler
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was useless here. because it is also done in _patch_django_asgi_handler().
Now the code is clean again and the "import channels" is only happening when there was this channels.http import before, so we do not need to guard it again.

except ImportError:
return
return

if not HAS_REAL_CONTEXTVARS:
# We better have contextvars or we're going to leak state between
# requests.
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/django/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ async def sentry_patched_get_response_async(self, request):

def patch_channels_asgi_handler_impl(cls):
# type: (Any) -> None

import channels # type: ignore

from sentry_sdk.integrations.django import DjangoIntegration

if channels.__version__ < "3.0.0":
Expand Down
Loading