From ecbf353a79e7ca2b7952b8a084c57abccc8d7b15 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 29 Mar 2024 07:08:09 +0000 Subject: [PATCH] Fixed URLRouter compatibility with Django main, pre-5.1 (#2085) --- channels/routing.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/channels/routing.py b/channels/routing.py index efb428ac9..07b5bab78 100644 --- a/channels/routing.py +++ b/channels/routing.py @@ -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 @@ -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(