#36703: Undocumented change of SetPasswordForm in django 5.1 release notes
-------------------------------------+-------------------------------------
Reporter: Laurent Bergeron | Owner: (none)
Type: Uncategorized | Status: new
Component: Documentation | Version: 5.1
Severity: Normal | Resolution:
Keywords: Authentication, | Triage Stage:
Forms | Unreviewed
Has patch: 0 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Laurent Bergeron):
Replying to [comment:2 ontowhee]:
> Hello! It looks like the changes were from #34429, and the release note
you linked mentions `The new AdminUserCreationForm and the existing
AdminPasswordChangeForm now support disabling password-based
authentication by setting an unusable password on form save.`
Yeah that seems to be it.
> Can you provide reproduction steps?
I created a custom password change form which had a clean method that
looked like this:
{{{
def clean(self):
if "new_password2" in self.errors:
new_password2_errors = self.errors["new_password2"].as_data()
for error in new_password2_errors:
if error.code in self.error_messages:
custom_error_message = self.error_messages[error.code]
error.message = custom_error_message
return super().clean()
}}}
And there is a dictionary in the form class that contains custom error
messages (self.error_messages) too.
But then I updated Django and this method couldn't change any error
messages because the errors on new_password2 (and other field I believe)
are now raised in super().clean(). The method worked before I updated
though as the errors were raised before my clean method.
To solve the issue I edited my method so it looks like this:
{{{
def clean(self):
super().clean()
if "new_password2" in self.errors:
new_password2_errors = self.errors["new_password2"].as_data()
for error in new_password2_errors:
if error.code in self.error_messages:
custom_error_message = self.error_messages[error.code]
error.message = custom_error_message
return self.cleaned_data
}}}
Now that super().clean() is executed before my error messages replacement
code, the latter works as expected. To be clear I didn't open this issue
to seek for help on how to solve this issue. I wanted to make sure this
change was detailed in the release notes.
--
Ticket URL: <https://code.djangoproject.com/ticket/36703#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019a45e0978d-cdb46a61-1525-44b3-8cf5-9028f57bd018-000000%40eu-central-1.amazonses.com.