-
-
Notifications
You must be signed in to change notification settings - Fork 348
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
Bug: ASGI mounted at base root ("/") intercepts dynamic path params #3535
Comments
Also worth noting that if the path isn't dynamic, it is not a problem - this is b/c we handle "plain" routes separately, and before we test for mounted paths: litestar/litestar/_asgi/routing_trie/traversal.py Lines 135 to 137 in f83c26f
We then test for mounted paths before we step through the route trie: litestar/litestar/_asgi/routing_trie/traversal.py Lines 139 to 155 in f83c26f
This is the source of the issue, b/c the dynamic route is only resolved as part of the trie traversal, but it never gets that far because the path So, I think we'd either need to get smarter with our |
Loosely related, we also cannot mount under a variable path, b/c the mount path regex includes the path variable placeholder, i.e., E.g., @asgi("/mounted/{num:int}", is_mount=True)
async def mounted(scope: Scope, receive: Receive, send: Send) -> None:
await send({"type": "http.response.start", "status": 200})
await send({"type": "http.response.body", "body": b"Mounted!"}) |
Maybe mounts should be routed during tree traversal, instead of separate from it. If we hit a node that has both a mount and child nodes with regular handlers, we try to route it further via the trie, and if that fails we then pipe it through the mount? |
I also came across this bug. Was going to file over at |
Sounds solid |
Going back to this, I'm having second thought if we actually want to allow this. Mounting ASGI apps at the root path is always going to be kinda weird and cause unexpected behaviour in some cases, because you then have two entry points for your application. Maybe we should just not allow this in the first place and save us a lot of trouble? |
Proposed a PR for sqladmin-litestar-plugin. I think mounting at "/" is wrong. |
Description
ASGI mounted at base root ("/") intercepts dynamic path params.
As explained by @peterschutt
peterschutt/sqladmin-litestar-plugin#11 (comment)
URL to code causing the issue
No response
MCVE
Steps to reproduce
Screenshots
"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"
Logs
No response
Litestar Version
2.8.2
Platform
Note
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.
Check out all issues funded or available for funding on our Polar.sh dashboard
The text was updated successfully, but these errors were encountered: