Fixed #28321 -- Prevented FormSet.full_clean() from adding errors from deleted forms.

This commit is contained in:
Windson yang 2017-07-25 06:55:41 +08:00 committed by Tim Graham
parent 28a02259cb
commit f32d24652b
2 changed files with 7 additions and 2 deletions

View File

@ -324,8 +324,12 @@ class BaseFormSet:
# Empty forms are unchanged forms beyond those with initial data. # Empty forms are unchanged forms beyond those with initial data.
if not form.has_changed() and i >= self.initial_form_count(): if not form.has_changed() and i >= self.initial_form_count():
empty_forms_count += 1 empty_forms_count += 1
# Accessing errors calls full_clean() if necessary.
self._errors.append(form.errors) # _should_delete_form() requires cleaned_data.
form_errors = form.errors
if self.can_delete and self._should_delete_form(form):
continue
self._errors.append(form_errors)
try: try:
if (self.validate_max and if (self.validate_max and
self.total_form_count() - len(self.deleted_forms) > self.max_num) or \ self.total_form_count() - len(self.deleted_forms) > self.max_num) or \

View File

@ -597,6 +597,7 @@ class FormsFormsetTestCase(SimpleTestCase):
'form-MIN_NUM_FORMS': 0, 'form-MAX_NUM_FORMS': 1}) 'form-MIN_NUM_FORMS': 0, 'form-MAX_NUM_FORMS': 1})
self.assertTrue(p.is_valid()) self.assertTrue(p.is_valid())
self.assertEqual(p._errors, [])
self.assertEqual(len(p.deleted_forms), 1) self.assertEqual(len(p.deleted_forms), 1)
def test_formsets_with_ordering(self): def test_formsets_with_ordering(self):