1
0
mirror of https://github.com/django/django.git synced 2025-10-26 07:06:08 +00:00

[1.11.x] Fixed #28159 -- Fixed BaseInlineFormSet._construct_form() crash when using save_as_new.

Regression in 4a246a02bd.

Backport of 362fba87c9 from master
This commit is contained in:
Alexander Kavanaugh
2017-05-01 16:58:28 -07:00
committed by Tim Graham
parent c5b7421068
commit 008ba77dfd
3 changed files with 16 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ from django.forms.models import (
BaseModelFormSet, _get_foreign_key, inlineformset_factory,
modelformset_factory,
)
from django.http import QueryDict
from django.test import TestCase, skipUnlessDBFeature
from django.utils import six
@@ -702,7 +703,9 @@ class ModelFormsetTest(TestCase):
AuthorBooksFormSet = inlineformset_factory(Author, Book, can_delete=False, extra=2, fields="__all__")
Author.objects.create(name='Charles Baudelaire')
data = {
# An immutable QueryDict simulates request.POST.
data = QueryDict(mutable=True)
data.update({
'book_set-TOTAL_FORMS': '3', # the number of forms rendered
'book_set-INITIAL_FORMS': '2', # the number of forms with initial data
'book_set-MAX_NUM_FORMS': '', # the max number of forms
@@ -711,10 +714,12 @@ class ModelFormsetTest(TestCase):
'book_set-1-id': '2',
'book_set-1-title': 'Les Paradis Artificiels',
'book_set-2-title': '',
}
})
data._mutable = False
formset = AuthorBooksFormSet(data, instance=Author(), save_as_new=True)
self.assertTrue(formset.is_valid())
self.assertIs(data._mutable, False)
new_author = Author.objects.create(name='Charles Baudelaire')
formset = AuthorBooksFormSet(data, instance=new_author, save_as_new=True)