Showing with 12 additions and 1 deletion.
  1. +1 −1 django/forms/models.py
  2. +11 −0 tests/regressiontests/model_formsets_regress/tests.py
View
2 django/forms/models.py
@@ -591,7 +591,7 @@ def get_form_error(self):
def save_existing_objects(self, commit=True):
self.changed_objects = []
self.deleted_objects = []
- if not self.get_queryset():
+ if not self.initial_forms:
return []
saved_instances = []
View
11 tests/regressiontests/model_formsets_regress/tests.py
@@ -249,6 +249,17 @@ def test_initial_data(self):
self.assertEqual(formset.extra_forms[0].initial['username'], "apollo11")
self.assertTrue(u'value="apollo12"' in formset.extra_forms[1].as_p())
+ def test_extraneous_query_is_not_run(self):
+ Formset = modelformset_factory(Network)
+ data = {u'test-TOTAL_FORMS': u'1',
+ u'test-INITIAL_FORMS': u'0',
+ u'test-MAX_NUM_FORMS': u'',
+ u'test-0-name': u'Random Place', }
+ with self.assertNumQueries(1):
+ formset = Formset(data, prefix="test")
+ formset.save()
+
+
class CustomWidget(forms.CharField):
pass

0 comments on commit 4d8a0f8

Please sign in to comment.