Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #19133 -- regression in UserChangeForm

  • Loading branch information...
commit 97d79b13ad6878474f6070a80ca45269b7e9a24f 1 parent bfcda77
@ptone authored
Showing with 20 additions and 3 deletions.
  1. +6 −3 django/contrib/auth/forms.py
  2. +14 −0 django/contrib/auth/tests/forms.py
View
9 django/contrib/auth/forms.py
@@ -52,9 +52,6 @@ def __init__(self, *args, **kwargs):
kwargs.setdefault("required", False)
super(ReadOnlyPasswordHashField, self).__init__(*args, **kwargs)
- def clean_password(self):
- return self.initial
-
class UserCreationForm(forms.ModelForm):
"""
@@ -121,6 +118,12 @@ class UserChangeForm(forms.ModelForm):
"this user's password, but you can change the password "
"using <a href=\"password/\">this form</a>."))
+ def clean_password(self):
+ # we clean the password here - as the readonly field/widget does not
+ # have access to the value
+ return self.initial["password"]
+
+
class Meta:
model = User
View
14 django/contrib/auth/tests/forms.py
@@ -265,6 +265,20 @@ def test_bug_17944_unknown_password_algorithm(self):
self.assertIn(_("Invalid password format or unknown hashing algorithm."),
form.as_table())
+ def test_regression_19133(self):
+ """
+ The change form does not return the password value
+ """
+ user = User.objects.get(username='testclient')
+ form_for_data = UserChangeForm(instance=user)
+ post_data = form_for_data.initial
+ # the readonly form does not return the password value
+ # it is fetched from the forms initial data
+ post_data['password'] = None
+ form = UserChangeForm(instance=user, data=post_data)
+ if form.is_valid():
+ form.save()
+
@skipIfCustomUser
@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
Please sign in to comment.
Something went wrong with that request. Please try again.