Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[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
  • Loading branch information...
commit 38056e82d70235129dd13e8e6f7d2d0e817e9bed 1 parent a67b35a
Russell Keith-Magee freakboy3742 authored
3  django/db/models/query.py
View
@@ -388,13 +388,14 @@ def delete(self):
# Delete objects in chunks to prevent the list of related objects from
# becoming too long.
seen_objs = None
+ del_itr = iter(del_query)
while 1:
# Collect a chunk of objects to be deleted, and then all the
# objects that are related to the objects that are to be deleted.
# The chunking *isn't* done by slicing the del_query because we
# need to maintain the query cache on del_query (see #12328)
seen_objs = CollectedObjects(seen_objs)
- for i, obj in izip(xrange(CHUNK_SIZE), del_query):
+ for i, obj in izip(xrange(CHUNK_SIZE), del_itr):
obj._collect_sub_objects(seen_objs)
if not seen_objs:
13 tests/regressiontests/delete_regress/tests.py
View
@@ -0,0 +1,13 @@
+import datetime
+
+from django.test import TestCase
+
+from models import Book
+
+class LargeDeleteTests(TestCase):
+ def test_large_deletes(self):
+ "Regression for #13309 -- if the number of objects > chunk size, deletion still occurs"
+ for x in range(300):
+ track = Book.objects.create(pagecount=x+100)
+ Book.objects.all().delete()
+ self.assertEquals(Book.objects.count(), 0)
Please sign in to comment.
Something went wrong with that request. Please try again.