mirror of
https://github.com/django/django.git
synced 2025-08-18 01:30:42 +00:00
Fixed #9479 -- Corrected an edge case in bulk queryset deletion that could cause an infinite loop when using MySQL InnoDB.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10913 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
be907bcdcb
commit
2416e5fefe
4 changed files with 78 additions and 2 deletions
|
@ -32,11 +32,21 @@ class CollectedObjects(object):
|
|||
|
||||
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):
|
||||
"""
|
||||
|
@ -53,6 +63,9 @@ class CollectedObjects(object):
|
|||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue