#36541 closed Cleanup/optimization (worksforme)
Using the `string_if_invalid` template configuration breaks the password reset button in the `UserAdmin`
Reported by: | Drew Winstel | Owned by: | |
---|---|---|---|
Component: | contrib.auth | Version: | 5.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Steps to replicate:
- Create any basic app (polls is fine) and add
path("admin/", admin.site.urls)
to your urlconf. - Set this template configuration in your settings.py:
TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", "OPTIONS": { "string_if_invalid": "INVALID EXPRESSION: %s", }, }, ]
- Navigate to the user detail view in the admin for any user
- Observe that the Reset password button renders to HTML as
<a class="button" href="INVALID EXPRESSION: password_url">Reset password</a>
which returns a 404 if you click on the button
This is because the default template for the password reset button looks for the password_url
template context, which isn't set at all by default. However, when you have string_if_invalid
set, password_url
resolves to the fallback string, preventing the default
filter from returning the correct value.
There are two workarounds:
- Find a way to inject a
password_url
into your context that gets set in the context - Override the
read_only_password_hash.html
template locally to hard-code the link to point to../password/
Change History (2)
comment:1 by , 7 weeks ago
Component: | Uncategorized → contrib.auth |
---|---|
Resolution: | → worksforme |
Status: | new → closed |
Type: | Uncategorized → Cleanup/optimization |
comment:2 by , 7 weeks ago
Thanks, Natalia! I'll do some more digging and see if I can get a full repro case up.
Note:
See TracTickets
for help on using tickets.
Hello Drew! Thank you for taking the time to create this ticket. I see your point and I agree that not having a
password_url
defined is an issue we could/should improve. But I have not been able to reproduce what you see. See my two attempts below:TEMPLATES
settings like this:And while I do see the
string_if_invalid
used in my app templates, it's not used in the admin templates. I debugged for a while and I see that the engine being used to render the admin has a slightly different definition of the one used for my site templates. Could you please the exact setting definition that you are using?INVALID STRING
is printed in the password URL):tests/auth_tests/test_views.py
I'll close as
worksforme
for now, but please reopen when you can provide further details or a way to reproduce. Thanks again!