Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #15349 - Bound FormSet produces bound empty_form

Thanks to hidde-jan for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15614 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c411377bd56e0f97c56a3f9c13f0b7a435906dd9 1 parent 13f9fd3
Luke Plant authored
3  django/forms/formsets.py
@@ -144,9 +144,6 @@ def _get_empty_form(self, **kwargs):
144 144
             'prefix': self.add_prefix('__prefix__'),
145 145
             'empty_permitted': True,
146 146
         }
147  
-        if self.is_bound:
148  
-            defaults['data'] = self.data
149  
-            defaults['files'] = self.files
150 147
         defaults.update(kwargs)
151 148
         form = self.form(**defaults)
152 149
         self.add_fields(form, None)
22  tests/regressiontests/forms/tests/formsets.py
@@ -878,6 +878,28 @@ def test_form_errors_are_cought_by_formset(self):
878 878
         self.assertFalse(formset.is_valid())
879 879
         self.assertEquals([{}, {'pub_date': [u'This field is required.']}], formset.errors)
880 880
 
  881
+    def test_empty_forms_are_unbound(self):
  882
+        data = {
  883
+            'form-TOTAL_FORMS': u'1',
  884
+            'form-INITIAL_FORMS': u'0',
  885
+            'form-0-title': u'Test',
  886
+            'form-0-pub_date': u'1904-06-16',
  887
+        }
  888
+        unbound_formset = ArticleFormSet()
  889
+        bound_formset = ArticleFormSet(data)
  890
+
  891
+        empty_forms = []
  892
+
  893
+        empty_forms.append(unbound_formset.empty_form)
  894
+        empty_forms.append(bound_formset.empty_form)
  895
+
  896
+        # Empty forms should be unbound
  897
+        self.assertFalse(empty_forms[0].is_bound)
  898
+        self.assertFalse(empty_forms[1].is_bound)
  899
+
  900
+        # The empty forms should be equal.
  901
+        self.assertEqual(empty_forms[0].as_p(), empty_forms[1].as_p())
  902
+
881 903
 class TestEmptyFormSet(TestCase): 
882 904
     "Test that an empty formset still calls clean()"
883 905
     def test_empty_formset_is_valid(self): 

0 notes on commit c411377

Please sign in to comment.
Something went wrong with that request. Please try again.