From 008ba77dfd23576a8080f05e3c45a19da73b20ba Mon Sep 17 00:00:00 2001 From: Alexander Kavanaugh Date: Mon, 1 May 2017 16:58:28 -0700 Subject: [1.11.x] Fixed #28159 -- Fixed BaseInlineFormSet._construct_form() crash when using save_as_new. Regression in 4a246a02bdcbc13b15480c014f51cb0682af7c1e. Backport of 362fba87c9bb4f88542ba82ce4a732fed2634be7 from master --- django/forms/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'django') diff --git a/django/forms/models.py b/django/forms/models.py index af324c2b27..ed9df60321 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -894,12 +894,17 @@ class BaseInlineFormSet(BaseModelFormSet): def _construct_form(self, i, **kwargs): form = super(BaseInlineFormSet, self)._construct_form(i, **kwargs) if self.save_as_new: + mutable = getattr(form.data, '_mutable', None) + # Allow modifying an immutable QueryDict. + if mutable is not None: + form.data._mutable = True # Remove the primary key from the form's data, we are only # creating new instances form.data[form.add_prefix(self._pk_field.name)] = None - # Remove the foreign key from the form's data form.data[form.add_prefix(self.fk.name)] = None + if mutable is not None: + form.data._mutable = mutable # Set the fk value here so that the form can do its validation. fk_value = self.instance.pk -- cgit v1.3