Fixed #34349 -- Fixed FormSet.empty_form crash when deleting extra forms is disabled.

This commit is contained in:
Laurens Verhoeven 2023-02-17 21:05:00 +01:00 committed by Mariusz Felisiak
parent 278881e376
commit 6cbc403b8e
2 changed files with 4 additions and 1 deletions

View File

@ -490,7 +490,9 @@ class BaseFormSet(RenderableFormMixin):
required=False,
widget=self.get_ordering_widget(),
)
if self.can_delete and (self.can_delete_extra or index < initial_form_count):
if self.can_delete and (
self.can_delete_extra or (index is not None and index < initial_form_count)
):
form.fields[DELETION_FIELD_NAME] = BooleanField(
label=_("Delete"),
required=False,

View File

@ -1480,6 +1480,7 @@ class FormsFormsetTestCase(SimpleTestCase):
self.assertIn("DELETE", formset.forms[0].fields)
self.assertNotIn("DELETE", formset.forms[1].fields)
self.assertNotIn("DELETE", formset.forms[2].fields)
self.assertNotIn("DELETE", formset.empty_form.fields)
formset = ChoiceFormFormset(
data={