Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #13309 -- Ensure that delete() deletes everything it sh…

…ould delete(). Thanks to craig.kimerer@gmail.com for the report

Backport of r12941 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12955 bcc190cf-cafb-0310-a4f2-bffc1f526a37
commit 38056e82d70235129dd13e8e6f7d2d0e817e9bed 1 parent a67b35a
Russell Keith-Magee authored April 12, 2010
3  django/db/models/query.py
@@ -388,13 +388,14 @@ def delete(self):
388 388
         # Delete objects in chunks to prevent the list of related objects from
389 389
         # becoming too long.
390 390
         seen_objs = None
  391
+        del_itr = iter(del_query)
391 392
         while 1:
392 393
             # Collect a chunk of objects to be deleted, and then all the
393 394
             # objects that are related to the objects that are to be deleted.
394 395
             # The chunking *isn't* done by slicing the del_query because we
395 396
             # need to maintain the query cache on del_query (see #12328)
396 397
             seen_objs = CollectedObjects(seen_objs)
397  
-            for i, obj in izip(xrange(CHUNK_SIZE), del_query):
  398
+            for i, obj in izip(xrange(CHUNK_SIZE), del_itr):
398 399
                 obj._collect_sub_objects(seen_objs)
399 400
 
400 401
             if not seen_objs:
13  tests/regressiontests/delete_regress/tests.py
... ...
@@ -0,0 +1,13 @@
  1
+import datetime
  2
+
  3
+from django.test import TestCase
  4
+
  5
+from models import Book
  6
+
  7
+class LargeDeleteTests(TestCase):
  8
+    def test_large_deletes(self):
  9
+        "Regression for #13309 -- if the number of objects > chunk size, deletion still occurs"
  10
+        for x in range(300):
  11
+            track = Book.objects.create(pagecount=x+100)
  12
+        Book.objects.all().delete()
  13
+        self.assertEquals(Book.objects.count(), 0)

0 notes on commit 38056e8

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