3 ms·
Getting an error instead of the incorrect data because the route that was actually ran was another one is pretty good for debugging. I have actually ran into th
by vhcr 3y ago
Getting an error instead of the incorrect data because the route that was actually ran was another one is pretty good for debugging. I have actually ran into this with Django, one route was missing the ending "$" regex.
- danpalmer 3y agoI get the frustration, but URL routing correctness is fairly trivially tested in Django and other frameworks to work around this issue, whereas it sounds like the matching algorithm here simply does not support certain common use-cases.
- badrequest 3y agoWhat common use-cases does it not support?
- danpalmer 3y agoThe `/foo/bar` and `/foo/*` use-case, where you want the first to go to a special page and the latter to go to some regular page. Perhaps the former is hard-coded/static and the latter looks up some URL parameter in a database. You can of course always implement this within `/foo/*`, but then you're implementing your own URL routing and working around the framework rather than working inside the framework. This feels to me like it's a change designed for APIs, not a change designed for user-facing websites. For APIs URL structure is often well defined in a technical sense, and this sort of use-case is rare. For a user-facing site however there are UX concerns, marketing concerns, SEO concerns, all sorts of reasons why some lovely, technically correct REST-style URL structure just won't work in practice. Unfortunately I know this from experience.
- lelanthran 3y agoI understood what you were saying but it might be easier to read if you escaped the * characters.
- danpalmer 3y agoHa! Whoops! Thanks
- assbuttbuttass 3y agoI'm pretty sure that example worked even before the recent changes. From the documentation: > Longer patterns take precedence over shorter ones, so that if there are handlers registered for both "/images/" and "/images/thumbnails/", the latter handler will be called for paths beginning with "/images/thumbnails/" and the former will receive requests for any other paths in the "/images/" subtree.
- superb_dev 3y agoThe two routes `/foo/bar` and `/foo/*` are not ambiguous and would be allowed by the router
- danpalmer 3y agoAre they? It seems that the latter matches the former. i.e. for the path `/foo/bar` there are 2 matching routes. One must take precedence, but this router doesn't appear to allow that. This may just be a syntax thing, I was being loose with syntax, and meant that the `*` would match anything for the purposes of this example.
- pipe01 3y agoIt does allow that, the one without wildcards is more specific so it'll pick that one
- greiskul 3y agoThis work, the panic is only triggered when the precedence rules can't fix a conflict. The behaviour documented here is actually extremely sensible and is best practices for anyone calling themselves a software engineer. Fail as early as possible, with as clear a message as possible.
- the_gipsy 3y agoBut there is a precedence to pick for the panic case too.
- badrequest 3y agoThis pattern already works and would work with this change, you'd just need to define `/foo/bar` first.