Fixed #29459 -- Initialized form data/files with empty MultiValueDicts.

This commit is contained in:
Andra Denis Ionescu 2019-03-05 16:41:08 +01:00 committed by Tim Graham
parent 163236ea0e
commit 4c086d7da4
2 changed files with 8 additions and 2 deletions

View File

@ -11,6 +11,7 @@ from django.forms.fields import Field, FileField
# pretty_name is imported for backwards compatibility in Django 1.9 # pretty_name is imported for backwards compatibility in Django 1.9
from django.forms.utils import ErrorDict, ErrorList, pretty_name # NOQA from django.forms.utils import ErrorDict, ErrorList, pretty_name # NOQA
from django.forms.widgets import Media, MediaDefiningClass from django.forms.widgets import Media, MediaDefiningClass
from django.utils.datastructures import MultiValueDict
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.html import conditional_escape, html_safe from django.utils.html import conditional_escape, html_safe
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
@ -69,8 +70,8 @@ class BaseForm:
initial=None, error_class=ErrorList, label_suffix=None, initial=None, error_class=ErrorList, label_suffix=None,
empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None): empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None):
self.is_bound = data is not None or files is not None self.is_bound = data is not None or files is not None
self.data = {} if data is None else data self.data = MultiValueDict() if data is None else data
self.files = {} if files is None else files self.files = MultiValueDict() if files is None else files
self.auto_id = auto_id self.auto_id = auto_id
if prefix is not None: if prefix is not None:
self.prefix = prefix self.prefix = prefix

View File

@ -3671,6 +3671,11 @@ Good luck picking a username that doesn&#39;t already exist.</p>
self.assertTrue(f.is_valid()) self.assertTrue(f.is_valid())
self.assertEqual(f.cleaned_data, {'data': 'xyzzy'}) self.assertEqual(f.cleaned_data, {'data': 'xyzzy'})
def test_empty_data_files_multi_value_dict(self):
p = Person()
self.assertIsInstance(p.data, MultiValueDict)
self.assertIsInstance(p.files, MultiValueDict)
class CustomRenderer(DjangoTemplates): class CustomRenderer(DjangoTemplates):
pass pass