Author: russellm
Date: 2009-06-03 08:43:05 -0500 (Wed, 03 Jun 2009)
New Revision: 10915

Added:
   django/branches/releases/1.0.X/tests/regressiontests/delete_regress/
   
django/branches/releases/1.0.X/tests/regressiontests/delete_regress/__init__.py
   django/branches/releases/1.0.X/tests/regressiontests/delete_regress/models.py
Removed:
   
django/branches/releases/1.0.X/tests/regressiontests/delete_regress/__init__.py
   django/branches/releases/1.0.X/tests/regressiontests/delete_regress/models.py
Modified:
   django/branches/releases/1.0.X/
   django/branches/releases/1.0.X/django/db/models/query.py
Log:
[1.0.X] Fixed #9479 -- Corrected an edge case in bulk queryset deletion that 
could cause an infinite loop when using MySQL InnoDB.

Merge of 10913-10914 from trunk.



Property changes on: django/branches/releases/1.0.X
___________________________________________________________________
Name: svnmerge-integrated
   - 
/django/trunk:1-9097,9099-9102,9104-9109,9111,9113-9144,9146-9151,9153-9156,9158-9159,9161-9187,9189-9247,9249-9262,9264-9277,9279-9298,9301-9302,9305-9331,9333-9343,9345,9347,9350-9352,9355-9396,9399-9462,9466-9469,9471-9488,9491-9526,9529,9533-9536,9539-9550,9556-9557,9559-9560,9562-9568,9570-9591,9595-9619,9621-9624,9626-9636,9638-9642,9644-9645,9647-9689,9691-9699,9703-9706,9709-9713,9716-9723,9725-9726,9730-9738,9740-9741,9750-9751,9757-9758,9761-9762,9767-9768,9770-9780,9782-9784,9789-9790,9793-9798,9801-9802,9806-9807,9809-9813,9821-9837,9842-9843,9847-9859,9861,9863-9875,9877-9881,9883-9887,9899-9903,9906-9909,9912,9914,9916-9917,9919-9920,9922-9927,9929,9931-9937,9939,9942-9943,9945-9950,9953-9954,9956-9962,9966-9977,9979-9984,9986-9988,9990-10001,10003-10004,10007,10009-10010,10013-10017,10019-10020,10022-10025,10031,10036-10041,10049-10052,10054-10061,10066-10069,10071-10076,10078-10079,10085-10087,10104,10106,10125-10127,10136,10138-10140,10143,10145-10147,10149-10160,10163-10167,10170,10173,10175-10176,10180,10185,10189,10192-10196,10198-10221,10223-10228,10230-10234,10236-10247,10250-10257,10259-10270,10273-10274,10276-10280,10282-10314,10316,10319-10322,10324-10325,10328-10329,10333-10344,10348-10351,10353-10356,10358-10363,10365-10368,10371-10380,10386-10407,10411,10413-10427,10429-10437,10440-10442,10444-10445,10447-10450,10452-10453,10457-10464,10466-10467,10469-10480,10482-10485,10489-10492,10495-10497,10499-10505,10508-10509,10511-10514,10517-10520,10524-10525,10528,10530-10537,10539-10548,10550-10557,10561,10563-10564,10567-10571,10573-10574,10576-10578,10580-10589,10591-10592,10595-10596,10599-10601,10603-10620,10624-10626,10631,10639-10641,10643,10646,10652-10655,10659-10660,10666-10669,10675,10682-10690,10693,10697-10704,10707,10713-10714,10723,10725,10727,10729,10732,10743-10750,10752-10760,10768,10770,10772,10774,10777,10782,10787,10789,10791,10795,10797,10799,10801,10805,10808,10810,10812,10814,10816,10819,10822,10828,10831,10833,10835,10837,10841,10843,10845,10847,10849
   + 
/django/trunk:1-9097,9099-9102,9104-9109,9111,9113-9144,9146-9151,9153-9156,9158-9159,9161-9187,9189-9247,9249-9262,9264-9277,9279-9298,9301-9302,9305-9331,9333-9343,9345,9347,9350-9352,9355-9396,9399-9462,9466-9469,9471-9488,9491-9526,9529,9533-9536,9539-9550,9556-9557,9559-9560,9562-9568,9570-9591,9595-9619,9621-9624,9626-9636,9638-9642,9644-9645,9647-9689,9691-9699,9703-9706,9709-9713,9716-9723,9725-9726,9730-9738,9740-9741,9750-9751,9757-9758,9761-9762,9767-9768,9770-9780,9782-9784,9789-9790,9793-9798,9801-9802,9806-9807,9809-9813,9821-9837,9842-9843,9847-9859,9861,9863-9875,9877-9881,9883-9887,9899-9903,9906-9909,9912,9914,9916-9917,9919-9920,9922-9927,9929,9931-9937,9939,9942-9943,9945-9950,9953-9954,9956-9962,9966-9977,9979-9984,9986-9988,9990-10001,10003-10004,10007,10009-10010,10013-10017,10019-10020,10022-10025,10031,10036-10041,10049-10052,10054-10061,10066-10069,10071-10076,10078-10079,10085-10087,10104,10106,10125-10127,10136,10138-10140,10143,10145-10147,10149-10160,10163-10167,10170,10173,10175-10176,10180,10185,10189,10192-10196,10198-10221,10223-10228,10230-10234,10236-10247,10250-10257,10259-10270,10273-10274,10276-10280,10282-10314,10316,10319-10322,10324-10325,10328-10329,10333-10344,10348-10351,10353-10356,10358-10363,10365-10368,10371-10380,10386-10407,10411,10413-10427,10429-10437,10440-10442,10444-10445,10447-10450,10452-10453,10457-10464,10466-10467,10469-10480,10482-10485,10489-10492,10495-10497,10499-10505,10508-10509,10511-10514,10517-10520,10524-10525,10528,10530-10537,10539-10548,10550-10557,10561,10563-10564,10567-10571,10573-10574,10576-10578,10580-10589,10591-10592,10595-10596,10599-10601,10603-10620,10624-10626,10631,10639-10641,10643,10646,10652-10655,10659-10660,10666-10669,10675,10682-10690,10693,10697-10704,10707,10713-10714,10723,10725,10727,10729,10732,10743-10750,10752-10760,10768,10770,10772,10774,10777,10782,10787,10789,10791,10795,10797,10799,10801,10805,10808,10810,10812,10814,10816,10819,10822,10828,10831,10833,10835,10837,10841,10843,10845,10847,10849,10913-10914

Modified: django/branches/releases/1.0.X/django/db/models/query.py
===================================================================
--- django/branches/releases/1.0.X/django/db/models/query.py    2009-06-03 
13:32:26 UTC (rev 10914)
+++ django/branches/releases/1.0.X/django/db/models/query.py    2009-06-03 
13:43:05 UTC (rev 10915)
@@ -37,11 +37,21 @@
 
     This is used for the database object deletion routines so that we can
     calculate the 'leaf' objects which should be deleted first.
+
+    previously_seen is an optional argument. It must be a CollectedObjects
+    instance itself; any previously_seen collected object will be blocked from
+    being added to this instance.
     """
 
-    def __init__(self):
+    def __init__(self, previously_seen=None):
         self.data = {}
         self.children = {}
+        if previously_seen:
+            self.blocked = previously_seen.blocked
+            for cls, seen in previously_seen.data.items():
+                self.blocked.setdefault(cls, SortedDict()).update(seen)
+        else:
+            self.blocked = {}
 
     def add(self, model, pk, obj, parent_model, nullable=False):
         """
@@ -58,6 +68,9 @@
         Returns True if the item already existed in the structure and
         False otherwise.
         """
+        if pk in self.blocked.get(model, {}):
+            return True
+
         d = self.data.setdefault(model, SortedDict())
         retval = pk in d
         d[pk] = obj
@@ -390,10 +403,11 @@
 
         # Delete objects in chunks to prevent the list of related objects from
         # becoming too long.
+        seen_objs = None
         while 1:
             # Collect all the objects to be deleted in this chunk, and all the
             # objects that are related to the objects that are to be deleted.
-            seen_objs = CollectedObjects()
+            seen_objs = CollectedObjects(seen_objs)
             for object in del_query[:CHUNK_SIZE]:
                 object._collect_sub_objects(seen_objs)
 

Copied: django/branches/releases/1.0.X/tests/regressiontests/delete_regress 
(from rev 10913, django/trunk/tests/regressiontests/delete_regress)


Property changes on: 
django/branches/releases/1.0.X/tests/regressiontests/delete_regress
___________________________________________________________________
Name: svn:ignore
   + *.pyc


Deleted: 
django/branches/releases/1.0.X/tests/regressiontests/delete_regress/__init__.py
===================================================================
--- django/trunk/tests/regressiontests/delete_regress/__init__.py       
2009-06-03 13:23:19 UTC (rev 10913)
+++ 
django/branches/releases/1.0.X/tests/regressiontests/delete_regress/__init__.py 
    2009-06-03 13:43:05 UTC (rev 10915)
@@ -1 +0,0 @@
-

Copied: 
django/branches/releases/1.0.X/tests/regressiontests/delete_regress/__init__.py 
(from rev 10913, django/trunk/tests/regressiontests/delete_regress/__init__.py)
===================================================================
--- 
django/branches/releases/1.0.X/tests/regressiontests/delete_regress/__init__.py 
                            (rev 0)
+++ 
django/branches/releases/1.0.X/tests/regressiontests/delete_regress/__init__.py 
    2009-06-03 13:43:05 UTC (rev 10915)
@@ -0,0 +1 @@
+

Deleted: 
django/branches/releases/1.0.X/tests/regressiontests/delete_regress/models.py
===================================================================
--- django/trunk/tests/regressiontests/delete_regress/models.py 2009-06-03 
13:23:19 UTC (rev 10913)
+++ 
django/branches/releases/1.0.X/tests/regressiontests/delete_regress/models.py   
    2009-06-03 13:43:05 UTC (rev 10915)
@@ -1,61 +0,0 @@
-from django.conf import settings
-from django.db import models, backend, connection, transaction
-from django.db.models import sql, query
-from django.test import TransactionTestCase
-
-class Book(models.Model):
-    pagecount = models.IntegerField()
-
-# Can't run this test under SQLite, because you can't
-# get two connections to an in-memory database.
-if settings.DATABASE_ENGINE != 'sqlite3':
-    class DeleteLockingTest(TransactionTestCase):
-        def setUp(self):
-            # Create a second connection to the database
-            self.conn2 = backend.DatabaseWrapper({
-                'DATABASE_HOST': settings.DATABASE_HOST,
-                'DATABASE_NAME': settings.DATABASE_NAME,
-                'DATABASE_OPTIONS': settings.DATABASE_OPTIONS,
-                'DATABASE_PASSWORD': settings.DATABASE_PASSWORD,
-                'DATABASE_PORT': settings.DATABASE_PORT,
-                'DATABASE_USER': settings.DATABASE_USER,
-                'TIME_ZONE': settings.TIME_ZONE,
-            })
-
-            # Put both DB connections into managed transaction mode
-            transaction.enter_transaction_management()
-            transaction.managed(True)
-            self.conn2._enter_transaction_management(True)
-
-        def tearDown(self):
-            # Close down the second connection.
-            transaction.leave_transaction_management()
-            self.conn2.close()
-
-        def test_concurrent_delete(self):
-            "Deletes on concurrent transactions don't collide and lock the 
database. Regression for #9479"
-
-            # Create some dummy data
-            b1 = Book(id=1, pagecount=100)
-            b2 = Book(id=2, pagecount=200)
-            b3 = Book(id=3, pagecount=300)
-            b1.save()
-            b2.save()
-            b3.save()
-
-            transaction.commit()
-
-            self.assertEquals(3, Book.objects.count())
-
-            # Delete something using connection 2.
-            cursor2 = self.conn2.cursor()
-            cursor2.execute('DELETE from delete_regress_book WHERE id=1')
-            self.conn2._commit();
-
-            # Now perform a queryset delete that covers the object
-            # deleted in connection 2. This causes an infinite loop
-            # under MySQL InnoDB unless we keep track of already
-            # deleted objects.
-            Book.objects.filter(pagecount__lt=250).delete()
-            transaction.commit()
-            self.assertEquals(1, Book.objects.count())

Copied: 
django/branches/releases/1.0.X/tests/regressiontests/delete_regress/models.py 
(from rev 10913, django/trunk/tests/regressiontests/delete_regress/models.py)
===================================================================
--- 
django/branches/releases/1.0.X/tests/regressiontests/delete_regress/models.py   
                            (rev 0)
+++ 
django/branches/releases/1.0.X/tests/regressiontests/delete_regress/models.py   
    2009-06-03 13:43:05 UTC (rev 10915)
@@ -0,0 +1,53 @@
+from django.conf import settings
+from django.db import models, backend, connection, transaction
+from django.db.models import sql, query
+from django.test import TestCase
+
+class Book(models.Model):
+    pagecount = models.IntegerField()
+
+# Can't run this test under SQLite, because you can't
+# get two connections to an in-memory database.
+if settings.DATABASE_ENGINE != 'sqlite3':
+    class DeleteLockingTest(TestCase):
+        def setUp(self):
+            # Create a second connection to the database
+            self.conn2 = backend.DatabaseWrapper(**settings.DATABASE_OPTIONS)
+
+            # Put both DB connections into managed transaction mode
+            transaction.enter_transaction_management()
+            transaction.managed(True)
+            # self.conn2._enter_transaction_management(True)
+
+        def tearDown(self):
+            # Close down the second connection.
+            transaction.leave_transaction_management()
+            self.conn2.close()
+
+        def test_concurrent_delete(self):
+            "Deletes on concurrent transactions don't collide and lock the 
database. Regression for #9479"
+
+            # Create some dummy data
+            b1 = Book(id=1, pagecount=100)
+            b2 = Book(id=2, pagecount=200)
+            b3 = Book(id=3, pagecount=300)
+            b1.save()
+            b2.save()
+            b3.save()
+
+            transaction.commit()
+
+            self.assertEquals(3, Book.objects.count())
+
+            # Delete something using connection 2.
+            cursor2 = self.conn2.cursor()
+            cursor2.execute('DELETE from delete_regress_book WHERE id=1')
+            self.conn2._commit();
+
+            # Now perform a queryset delete that covers the object
+            # deleted in connection 2. This causes an infinite loop
+            # under MySQL InnoDB unless we keep track of already
+            # deleted objects.
+            Book.objects.filter(pagecount__lt=250).delete()
+            transaction.commit()
+            self.assertEquals(1, Book.objects.count())


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to