Opened 3 days ago
Last modified 25 hours ago
#36796 assigned Bug
URL resolution breaks if route defined with lazy string and uses an include
| Reported by: | Andrea Angelini | Owned by: | Kundan Yadav |
|---|---|---|---|
| Component: | Core (URLs) | Version: | 6.0 |
| Severity: | Release blocker | Keywords: | gettext_lazy, lazy |
| Cc: | Andrea Angelini, Jake Howard | Triage Stage: | Accepted |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
After this commit:
https://github.com/django/django/commit/f920937c8a63df6bea220e4386f59cdb45b2e355
this is not working if self._route is gettext_lazy('test'):
elif path.startswith(self._route):
return path.removeprefix(self._route), (), {}
More info here:
https://forum.djangoproject.com/t/gettext-lazy-and-url-patterns/43703
Change History (7)
comment:1 by , 3 days ago
| Cc: | added |
|---|---|
| Type: | Uncategorized → Bug |
comment:2 by , 3 days ago
| Cc: | added |
|---|---|
| Keywords: | gettext_lazy lazy added |
| Severity: | Normal → Release blocker |
| Summary: | gettext_lazy and url patterns → URL resolution breaks if route defined with lazy string and uses an include |
| Triage Stage: | Unreviewed → Accepted |
comment:3 by , 3 days ago
Amended like following fixes this issue:
elif path.startswith(str(self._route)):
return path.removeprefix(str(self._route)), (), {}
comment:4 by , 3 days ago
I'd missed that lazy string were accepted, and surprised a test didn't cover this behaviour.
Just handling the elif case won't quite work, since there's also the endpoint case. Converting self._route to a string (as part of match, rather than the constructor so it's evaluated in the correct context) sounds like the right solution. It'd be nice if the conversion only happens once per match to avoid unnecessary extra work.
comment:5 by , 3 days ago
I agree with you that it should be converted to a string as part of match and not as I proposed here
comment:6 by , 3 days ago
In the endpoint seems to work though because gettext_lazy('test') == 'test' return True
comment:7 by , 25 hours ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
Thanks, replicated like this (traceback given in forum post):
It's documented that the
routearg topath()can take a lazy string.