From 1aa8e8605cca95b31eaf6f5e47bc0742d6f2e0c7 Mon Sep 17 00:00:00 2001 From: Stefan Wehrmeyer Date: Tue, 28 Mar 2017 12:27:49 -0400 Subject: [PATCH] Fixed #27989 -- Preserved empty QueryDicts for form's data/files args. --- django/forms/forms.py | 4 ++-- tests/forms_tests/tests/test_forms.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/django/forms/forms.py b/django/forms/forms.py index caf4617c22..80613570ad 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -76,8 +76,8 @@ class BaseForm: initial=None, error_class=ErrorList, label_suffix=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.data = data or {} - self.files = files or {} + self.data = {} if data is None else data + self.files = {} if files is None else files self.auto_id = auto_id if prefix is not None: self.prefix = prefix diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index df6518b933..2466bbc67b 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -164,6 +164,13 @@ class FormsTestCase(SimpleTestCase):

""" ) + def test_empty_querydict_args(self): + data = QueryDict() + files = QueryDict() + p = Person(data, files) + self.assertIs(p.data, data) + self.assertIs(p.files, files) + def test_unbound_form(self): # If you don't pass any values to the Form's __init__(), or if you pass None, # the Form will be considered unbound and won't do any validation. Form.errors