Skip to content
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

URLRouter doesn't build paths with root_path from scope #1973

Closed
ajslater opened this issue Feb 7, 2023 · 2 comments
Closed

URLRouter doesn't build paths with root_path from scope #1973

ajslater opened this issue Feb 7, 2023 · 2 comments

Comments

@ajslater
Copy link

ajslater commented Feb 7, 2023

It seems to me that here: https://github.com/django/channels/blob/main/channels/routing.py#L100

URLRouter should strip the scope['root_path'] from the submitted path for matching against paths.

Django does this for path matching.

Workaround

Manually add the configured asgi root_path to the head of all paths submitted to the UrlRouter().

e.g.

PREFIX = HYPERCORN_CONFIG.root_path[1:] + "/" if HYPERCORN_CONFIG.root_path else ""

URLRouter([
    path(f"{PREFIX}ws", MyConsumer.as_asgi()),  
])
@carltongibson
Copy link
Member

Fixed in #1954

@ajslater
Copy link
Author

ajslater commented Apr 4, 2024

This is fixed. Thank you!

In related news, the Django router also stopped setting script_prefix from scope root_path two months ago. This is not Channels' problem, but might be relevant to anyone searching on this bug.
A workaround is attached to this bug report: https://code.djangoproject.com/ticket/35169#comment:11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants