Skip to content
Browse files

[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...
1 parent 0e4d8d4 commit ebd0a6a09ff95d42b0feec82d8509ffa009eb05b @freakboy3742 freakboy3742 committed
Showing with 28 additions and 2 deletions.
  1. +2 −2 django/forms/models.py
  2. +26 −0 tests/regressiontests/model_formsets_regress/tests.py
View
4 django/forms/models.py
@@ -522,7 +522,7 @@ def validate_unique(self):
# poke error messages into the right places and mark
# the form as invalid
errors.append(self.get_unique_error_message(unique_check))
- form._errors[NON_FIELD_ERRORS] = self.get_form_error()
+ form._errors[NON_FIELD_ERRORS] = self.error_class([self.get_form_error()])
del form.cleaned_data
break
# mark the data as seen
@@ -553,7 +553,7 @@ def validate_unique(self):
# poke error messages into the right places and mark
# the form as invalid
errors.append(self.get_date_error_message(date_check))
- form._errors[NON_FIELD_ERRORS] = self.get_form_error()
+ form._errors[NON_FIELD_ERRORS] = self.error_class([self.get_form_error()])
del form.cleaned_data
break
seen_data.add(data)
View
26 tests/regressiontests/model_formsets_regress/tests.py
@@ -1,4 +1,5 @@
from django import forms
+from django.forms.util import ErrorDict, ErrorList
from django.forms.models import modelform_factory, inlineformset_factory, modelformset_factory
from django.test import TestCase
@@ -192,6 +193,31 @@ def test_save_as_new_with_new_inlines(self):
["<Host: matrix.de.eu.dal.net>", "<Host: tranquility.hub.dal.net>"]
)
+class FormsetTests(TestCase):
+ def test_error_class(self):
+ '''
+ Test the type of Formset and Form error attributes
+ '''
+ Formset = modelformset_factory(User)
+ data = {
+ 'form-TOTAL_FORMS': u'2',
+ 'form-INITIAL_FORMS': u'0',
+ 'form-MAX_NUM_FORMS': u'0',
+ 'form-0-id': '',
+ 'form-0-username': u'apollo13',
+ 'form-0-serial': u'1',
+ 'form-1-id': '',
+ 'form-1-username': u'apollo13',
+ 'form-1-serial': u'2',
+ }
+ formset = Formset(data)
+ # check if the returned error classes are correct
+ # note: formset.errors returns a list as documented
+ self.assertTrue(isinstance(formset.errors, list))
+ self.assertTrue(isinstance(formset.non_form_errors(), ErrorList))
+ for form in formset.forms:
+ self.assertTrue(isinstance(form.errors, ErrorDict))
+ self.assertTrue(isinstance(form.non_field_errors(), ErrorList))
class CustomWidget(forms.CharField):
pass

0 comments on commit ebd0a6a

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