-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Fixed #35477 -- Fixed field required validation in forms inheriting from SetPassword. #18195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for the PR @fsbraun ⭐ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @fsbraun, thank you for your speedy work on this!
Could you please ensure that there is a test for every form inheriting from SetPasswordMixin
? (BaseUserCreationForm
, SetPasswordForm
and AdminPasswordChangeForm
)
f1d2ab9
to
1693f3b
Compare
@nessita Done! |
How do I install this version with pip? |
Try |
This version works. Thank you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @fsbraun, thanks for adding tests! Could you please rename and move each test to its specific test class? Otherwise we get tests for other forms inside SetPasswordFormTest
which is about the form and not the mixin.
The relevant test cases are:
SetPasswordFormTest
(forSetPasswordForm
)BaseUserCreationFormTest
(forBaseUserCreationForm
)AdminPasswordChangeFormTest
(forAdminPasswordChangeForm
)
I also added a comment about an untested change. Thank you! 🌟
35cf874
to
c1673d6
Compare
…ge forms. The auth forms using SetPasswordMixin were incorrectly including the 'This field is required.' error when additional validations (e.g., overriding `clean_password1`) were performed and failed. This fix ensures accurate error reporting for password fields. Co-authored-by: Natalia <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @fsbraun for the fixes.
I have made some tweaks because I wasn't comfortable with the weakening of the if guard to == ""
. Additionally, I removed the call to validate_password
in the custom forms (in the tests) as I think it caused some confusion. It was only when I realized that the specifics of what happens inside a clean_*
method are not relevant that I understood the important part: the key is to raise any validation error inside the clean field method, and so the password field is no longer present inside cleaned_data
leading to the fixed issue.
Trac ticket number
ticket-35477
Branch description
When adding additional validation to the
SetPassword
form indjango.contrib.auth
and they fail, the from's clean method assumed they were empty since it did only check for truthiness of the passwords.This PR changes the check for empty passwords to them being empty strings.
@sarahboyce Thanks for providing those helpful tests!!
Checklist
main
branch.