From 040c18b17e854459c9eff39a4dbbacf6b5460f31 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Fri, 9 Apr 2010 13:24:13 +0000 Subject: [PATCH] Fixed #13309 -- Ensure that delete() deletes everything it should delete(). Thanks to craig.kimerer@gmail.com for the report. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12941 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/query.py | 3 ++- tests/regressiontests/delete_regress/tests.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/django/db/models/query.py b/django/db/models/query.py index b8b2340b3f..ad6d37f631 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -429,13 +429,14 @@ class QuerySet(object): # 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: diff --git a/tests/regressiontests/delete_regress/tests.py b/tests/regressiontests/delete_regress/tests.py index 7ebe5e86a4..26cd3c5ce9 100644 --- a/tests/regressiontests/delete_regress/tests.py +++ b/tests/regressiontests/delete_regress/tests.py @@ -106,3 +106,11 @@ class DeleteCascadeTests(TestCase): self.assertEquals(PlayedWith.objects.count(), 0) # first two asserts just sanity checks, this is the kicker: self.assertEquals(PlayedWithNote.objects.count(), 0) + +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)