Skip to content

Commit

Permalink
Fixed URLRouter compatibility with Django main, pre-5.1 (#2085)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz authored Mar 29, 2024
1 parent acc9169 commit ecbf353
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions channels/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.urls.exceptions import Resolver404
from django.urls.resolvers import URLResolver
from django.urls.resolvers import RegexPattern, RoutePattern, URLResolver

"""
All Routing instances inside this file are also valid ASGI applications - with
Expand Down Expand Up @@ -87,7 +87,14 @@ def __init__(self, routes):
# The inner ASGI app wants to do additional routing, route
# must not be an endpoint
if getattr(route.callback, "_path_routing", False) is True:
route.pattern._is_endpoint = False
pattern = route.pattern
if isinstance(pattern, RegexPattern):
arg = pattern._regex
elif isinstance(pattern, RoutePattern):
arg = pattern._route
else:
raise ValueError(f"Unsupported pattern type: {type(pattern)}")
route.pattern = pattern.__class__(arg, pattern.name, is_endpoint=False)

if not route.callback and isinstance(route, URLResolver):
raise ImproperlyConfigured(
Expand Down

0 comments on commit ecbf353

Please sign in to comment.