Skip to content

Commit ecbf353

Browse files
authored
Fixed URLRouter compatibility with Django main, pre-5.1 (#2085)
1 parent acc9169 commit ecbf353

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

channels/routing.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from django.conf import settings
44
from django.core.exceptions import ImproperlyConfigured
55
from django.urls.exceptions import Resolver404
6-
from django.urls.resolvers import URLResolver
6+
from django.urls.resolvers import RegexPattern, RoutePattern, URLResolver
77

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

9299
if not route.callback and isinstance(route, URLResolver):
93100
raise ImproperlyConfigured(

0 commit comments

Comments
 (0)