Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed #15167 -- Ensure that non-form errors are always part o…

…f an ErrorList. Thanks to Harm Geerts for the report and patch.

Backport of r15424 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15425 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ebd0a6a09ff95d42b0feec82d8509ffa009eb05b 1 parent 0e4d8d4
Russell Keith-Magee authored February 05, 2011
4  django/forms/models.py
@@ -522,7 +522,7 @@ def validate_unique(self):
522 522
                         # poke error messages into the right places and mark
523 523
                         # the form as invalid
524 524
                         errors.append(self.get_unique_error_message(unique_check))
525  
-                        form._errors[NON_FIELD_ERRORS] = self.get_form_error()
  525
+                        form._errors[NON_FIELD_ERRORS] = self.error_class([self.get_form_error()])
526 526
                         del form.cleaned_data
527 527
                         break
528 528
                     # mark the data as seen
@@ -553,7 +553,7 @@ def validate_unique(self):
553 553
                         # poke error messages into the right places and mark
554 554
                         # the form as invalid
555 555
                         errors.append(self.get_date_error_message(date_check))
556  
-                        form._errors[NON_FIELD_ERRORS] = self.get_form_error()
  556
+                        form._errors[NON_FIELD_ERRORS] = self.error_class([self.get_form_error()])
557 557
                         del form.cleaned_data
558 558
                         break
559 559
                     seen_data.add(data)
26  tests/regressiontests/model_formsets_regress/tests.py
... ...
@@ -1,4 +1,5 @@
1 1
 from django import forms
  2
+from django.forms.util import ErrorDict, ErrorList
2 3
 from django.forms.models import modelform_factory, inlineformset_factory, modelformset_factory
3 4
 from django.test import TestCase
4 5
 
@@ -192,6 +193,31 @@ def test_save_as_new_with_new_inlines(self):
192 193
             ["<Host: matrix.de.eu.dal.net>", "<Host: tranquility.hub.dal.net>"]
193 194
             )
194 195
 
  196
+class FormsetTests(TestCase):
  197
+    def test_error_class(self):
  198
+        '''
  199
+        Test the type of Formset and Form error attributes
  200
+        '''
  201
+        Formset = modelformset_factory(User)
  202
+        data = {
  203
+            'form-TOTAL_FORMS': u'2',
  204
+            'form-INITIAL_FORMS': u'0',
  205
+            'form-MAX_NUM_FORMS': u'0',
  206
+            'form-0-id': '',
  207
+            'form-0-username': u'apollo13',
  208
+            'form-0-serial': u'1',
  209
+            'form-1-id': '',
  210
+            'form-1-username': u'apollo13',
  211
+            'form-1-serial': u'2',
  212
+        }
  213
+        formset = Formset(data)
  214
+        # check if the returned error classes are correct
  215
+        # note: formset.errors returns a list as documented
  216
+        self.assertTrue(isinstance(formset.errors, list))
  217
+        self.assertTrue(isinstance(formset.non_form_errors(), ErrorList))
  218
+        for form in formset.forms:
  219
+            self.assertTrue(isinstance(form.errors, ErrorDict))
  220
+            self.assertTrue(isinstance(form.non_field_errors(), ErrorList))
195 221
 
196 222
 class CustomWidget(forms.CharField):
197 223
     pass

0 notes on commit ebd0a6a

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