Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #14242 - UserChangeForm subclasses without 'user_permissions' f…

…ield causes KeyError

This was a regression introduced by [13683]

Thanks to adammckerlie@gmail.com for report.



git-svn-id: http://code.djangoproject.com/svn/django/trunk@13702 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 303bdc85a7a310efc28e2ee52a5e9607069bb335 1 parent 801bb14
Luke Plant spookylukey authored
4 django/contrib/auth/forms.py
View
@@ -54,7 +54,9 @@ class Meta:
def __init__(self, *args, **kwargs):
super(UserChangeForm, self).__init__(*args, **kwargs)
- self.fields['user_permissions'].queryset = self.fields['user_permissions'].queryset.select_related('content_type')
+ f = self.fields.get('user_permissions', None)
+ if f is not None:
+ f.queryset = f.queryset.select_related('content_type')
class AuthenticationForm(forms.Form):
"""
16 django/contrib/auth/tests/forms.py
View
@@ -199,6 +199,22 @@ def test_username_validity(self):
self.assertEqual(form['username'].errors,
[u'This value may contain only letters, numbers and @/./+/-/_ characters.'])
+ def test_bug_14242(self):
+ # A regression test, introduce by adding an optimization for the
+ # UserChangeForm.
+
+ class MyUserForm(UserChangeForm):
+ def __init__(self, *args, **kwargs):
+ super(MyUserForm, self).__init__(*args, **kwargs)
+ self.fields['groups'].help_text = 'These groups give users different permissions'
+
+ class Meta(UserChangeForm.Meta):
+ fields = ('groups',)
+
+ # Just check we can create it
+ form = MyUserForm({})
+
+
class PasswordResetFormTest(TestCase):
fixtures = ['authtestdata.json']
Please sign in to comment.
Something went wrong with that request. Please try again.