Comments (6)
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 /whatever/123
matches the mount path /
.
So, I think we'd either need to get smarter with our mount_paths_regex
so that it doesn't match on routes that are registered adjacent to the mounted application with variable paths, or, traverse the routing trie before checking for a match on a mount path, and only then try to match a mount path if we'd have otherwise thrown the 404.
from litestar.
Loosely related, we also cannot mount under a variable path, b/c the mount path regex includes the path variable placeholder, i.e., re.compile("/mounted/{num:int}")
doesn't match /mounted/123
.
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!"})
from litestar.
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?
from litestar.
I also came across this bug. Was going to file over at sqladmin-litestar-plugin
but found it's already been raised there and pushed over here.
from litestar.
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?
Sounds solid
from litestar.
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?
from litestar.
Related Issues (20)
- Enhancement: Add class and funcion name to `ImproperlyConfiguredException`s HOT 4
- Docs: little typo in documentation HOT 1
- Bug: normal usage of route handler decorators causes deprecation warnings HOT 2
- Bug(SQLAlchemy Plugin): Generic responses are not getting serialized HOT 2
- Unexpected behavior from `module_to_os_path` HOT 4
- Exceptions not showing full traceback HOT 2
- Enhancement: Support configuring Pydantic's `.model_validate(..., strict=True`) HOT 2
- Bug: openapi spec. generation does not respect Response status_code HOT 2
- Bug: exception_handlers are not applied when debug flag is False HOT 2
- Docs: Mention the possibility to use UUIDv6 and UUIDv7 bases on db models
- Enhancement: ExternalDocumentation for ScalarRenderPlugin HOT 2
- Docs: bad links in flask migration docs HOT 2
- Bug: Litestar crashes on initialization with Python 3.12.4 and a read-only root filesystem HOT 3
- Bug: multiple values for keyword arguments HOT 3
- Bug: type annotation needs local import to work with websocket_listener
- SerializationException: Unsupported type: <class 'geoalchemy2.elements.WKBElement'>
- Docs: typo in channels docs ``create_route_handlers`` -> ``create_ws_route_handlers`` HOT 9
- Enhancement: add after_startup and before_shutdown hooks
- Bug: docs website is not up-to-date HOT 3
- Bug: Custom plugin with lifespan breaks channel startup hook HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from litestar.