Fixed #33995 -- Fixed FormSet.empty_form crash when empty_permitted is passed to form_kwargs.

This commit is contained in:
DevilsAutumn 2022-09-09 15:21:41 +05:30 committed by Mariusz Felisiak
parent 6df9398cce
commit f3cd252cfc
2 changed files with 12 additions and 7 deletions

View File

@ -257,14 +257,15 @@ class BaseFormSet(RenderableFormMixin):
@property @property
def empty_form(self): def empty_form(self):
form = self.form( form_kwargs = {
auto_id=self.auto_id,
prefix=self.add_prefix("__prefix__"),
empty_permitted=True,
use_required_attribute=False,
**self.get_form_kwargs(None), **self.get_form_kwargs(None),
renderer=self.renderer, "auto_id": self.auto_id,
) "prefix": self.add_prefix("__prefix__"),
"empty_permitted": True,
"use_required_attribute": False,
"renderer": self.renderer,
}
form = self.form(**form_kwargs)
self.add_fields(form, None) self.add_fields(form, None)
return form return form

View File

@ -179,6 +179,10 @@ class FormsFormsetTestCase(SimpleTestCase):
self.assertTrue(hasattr(formset.empty_form, "custom_kwarg")) self.assertTrue(hasattr(formset.empty_form, "custom_kwarg"))
self.assertEqual(formset.empty_form.custom_kwarg, 1) self.assertEqual(formset.empty_form.custom_kwarg, 1)
def test_empty_permitted_ignored_empty_form(self):
formset = ArticleFormSet(form_kwargs={"empty_permitted": False})
self.assertIs(formset.empty_form.empty_permitted, True)
def test_formset_validation(self): def test_formset_validation(self):
# FormSet instances can also have an error attribute if validation failed for # FormSet instances can also have an error attribute if validation failed for
# any of the forms. # any of the forms.