Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17594 -- Stopped ModelFormset.save from running a SELECT query…

… by relying on the fact that the initial form is already set. Thanks, tswicegood.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17434 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4d8a0f8902dd55348fbaf897048bef1cba285f05 1 parent 52d72a5
Jannis Leidel authored February 04, 2012
2  django/forms/models.py
@@ -591,7 +591,7 @@ def get_form_error(self):
591 591
     def save_existing_objects(self, commit=True):
592 592
         self.changed_objects = []
593 593
         self.deleted_objects = []
594  
-        if not self.get_queryset():
  594
+        if not self.initial_forms:
595 595
             return []
596 596
 
597 597
         saved_instances = []
11  tests/regressiontests/model_formsets_regress/tests.py
@@ -249,6 +249,17 @@ def test_initial_data(self):
249 249
         self.assertEqual(formset.extra_forms[0].initial['username'], "apollo11")
250 250
         self.assertTrue(u'value="apollo12"' in formset.extra_forms[1].as_p())
251 251
 
  252
+    def test_extraneous_query_is_not_run(self):
  253
+        Formset = modelformset_factory(Network)
  254
+        data = {u'test-TOTAL_FORMS': u'1',
  255
+                u'test-INITIAL_FORMS': u'0',
  256
+                u'test-MAX_NUM_FORMS': u'',
  257
+                u'test-0-name': u'Random Place', }
  258
+        with self.assertNumQueries(1):
  259
+            formset = Formset(data, prefix="test")
  260
+            formset.save()
  261
+
  262
+
252 263
 class CustomWidget(forms.CharField):
253 264
     pass
254 265
 

0 notes on commit 4d8a0f8

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