summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAlexander Kavanaugh <alex@kavdev.io>2017-05-01 16:58:28 -0700
committerTim Graham <timograham@gmail.com>2017-05-03 08:59:41 -0400
commit008ba77dfd23576a8080f05e3c45a19da73b20ba (patch)
tree675f94fd9bd7813e0cb27dcccb58ab3c663c7d6f /django
parentc5b742106834dd295279f22dab91a8353ddcb8af (diff)
[1.11.x] Fixed #28159 -- Fixed BaseInlineFormSet._construct_form() crash when using save_as_new.
Regression in 4a246a02bdcbc13b15480c014f51cb0682af7c1e. Backport of 362fba87c9bb4f88542ba82ce4a732fed2634be7 from master
Diffstat (limited to 'django')
-rw-r--r--django/forms/models.py7
1 files changed, 6 insertions, 1 deletions
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