Naming of static routes should be unique by default
sjsadowski opened this issue · comments
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe.
After helping resolve the issue here: https://community.sanicframework.org/t/using-app-static-twice-reports-a-deprecation-warning/1146
Which stemmed from #2674 I believe that app.static() should have a unique name. All app.static() routes currently require a name="" parameter which defaults to "static". This causes a problem when name is not specified and there are multiple static routes.
Describe the solution you'd like
It might make sense to infer the default name from the path if a name is not provided, or to generate a purely random one as the name itself is largely inconsequential if not being set explicitly.
Additional context
No response
The route name is with url_for
so it would have to be constructed from (web side) path then and not be random. This is a breaking change for anyone currently using name "static" and some other path than "/", where the new name would be static.the.path.components.here
.
Somewhat related is that of having multiple decorators on a single function, or having identically named separate handler functions within the same app (possibly in different modules), as those would also cause duplicate names if not manually specified. I have not checked but perhaps Blueprints already add their own part to the name, avoiding duplicate names when Blueprints are combined.
A simple thing that is non-breaking and easy to implement is to improve the error message, so that users understand why there is a problem and what they need to change (i.e. add name= argument or not use same names for their separate handler functions).
Yes blueprints behave this way, and yes this will happen as its about to be enforced.