Skip to content

Commit

Permalink
Use Django internal ASGI handling from Channels version 4.0.0. (#1688)
Browse files Browse the repository at this point in the history
* From Channels 4.0.0 on it has no ASGI handling included but utilizes Django's own ASGI handling.
  • Loading branch information
antonpirker committed Oct 17, 2022
1 parent 3f89260 commit 9e1e760
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 14 additions & 7 deletions tests/integrations/django/myapp/routing.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import channels

from channels.http import AsgiHandler
from channels.routing import ProtocolTypeRouter

if channels.__version__ < "3.0.0":
channels_handler = AsgiHandler
else:
channels_handler = AsgiHandler()
try:
from channels.http import AsgiHandler

if channels.__version__ < "3.0.0":
django_asgi_app = AsgiHandler
else:
django_asgi_app = AsgiHandler()

except ModuleNotFoundError:
# Since channels 4.0 ASGI handling is done by Django itself
from django.core.asgi import get_asgi_application

django_asgi_app = get_asgi_application()

application = ProtocolTypeRouter({"http": channels_handler})
application = ProtocolTypeRouter({"http": django_asgi_app})
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ deps =

django-{1.11,2.0,2.1,2.2,3.0,3.1,3.2}: djangorestframework>=3.0.0,<4.0.0

{py3.7,py3.8,py3.9,py3.10}-django-{1.11,2.0,2.1,2.2,3.0,3.1,3.2}: channels>2
{py3.7,py3.8,py3.9,py3.10}-django-{1.11,2.0,2.1,2.2,3.0,3.1,3.2}: channels[daphne]>2
{py3.7,py3.8,py3.9,py3.10}-django-{1.11,2.0,2.1,2.2,3.0,3.1,3.2}: pytest-asyncio
{py2.7,py3.7,py3.8,py3.9,py3.10}-django-{1.11,2.2,3.0,3.1,3.2}: psycopg2-binary

Expand Down

0 comments on commit 9e1e760

Please sign in to comment.