Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored September 09, 2010
4  django/contrib/auth/forms.py
@@ -54,7 +54,9 @@ class Meta:
54 54
 
55 55
     def __init__(self, *args, **kwargs):
56 56
         super(UserChangeForm, self).__init__(*args, **kwargs)
57  
-        self.fields['user_permissions'].queryset = self.fields['user_permissions'].queryset.select_related('content_type')
  57
+        f = self.fields.get('user_permissions', None)
  58
+        if f is not None:
  59
+            f.queryset = f.queryset.select_related('content_type')
58 60
 
59 61
 class AuthenticationForm(forms.Form):
60 62
     """
16  django/contrib/auth/tests/forms.py
@@ -199,6 +199,22 @@ def test_username_validity(self):
199 199
         self.assertEqual(form['username'].errors,
200 200
                          [u'This value may contain only letters, numbers and @/./+/-/_ characters.'])
201 201
 
  202
+    def test_bug_14242(self):
  203
+        # A regression test, introduce by adding an optimization for the
  204
+        # UserChangeForm.
  205
+
  206
+        class MyUserForm(UserChangeForm):
  207
+            def __init__(self, *args, **kwargs):
  208
+                super(MyUserForm, self).__init__(*args, **kwargs)
  209
+                self.fields['groups'].help_text = 'These groups give users different permissions'
  210
+
  211
+            class Meta(UserChangeForm.Meta):
  212
+                fields = ('groups',)
  213
+
  214
+        # Just check we can create it
  215
+        form = MyUserForm({})
  216
+
  217
+
202 218
 class PasswordResetFormTest(TestCase):
203 219
 
204 220
     fixtures = ['authtestdata.json']

0 notes on commit 303bdc8

Please sign in to comment.
Something went wrong with that request. Please try again.