Fixed #24576 -- Made deletion of related objects deterministic.

This commit is contained in:
Laura Feier 2015-11-04 14:27:35 +02:00 committed by Tim Graham
parent 1f29164ced
commit 7862cbda86
2 changed files with 4 additions and 3 deletions

View File

@ -64,7 +64,7 @@ class Collector(object):
def __init__(self, using): def __init__(self, using):
self.using = using self.using = using
# Initially, {model: {instances}}, later values become lists. # Initially, {model: {instances}}, later values become lists.
self.data = {} self.data = OrderedDict()
self.field_updates = {} # {model: {(field, value): {instances}}} self.field_updates = {} # {model: {(field, value): {instances}}}
# fast_deletes is a list of queryset-likes that can be deleted without # fast_deletes is a list of queryset-likes that can be deleted without
# fetching the objects into memory. # fetching the objects into memory.

View File

@ -224,12 +224,13 @@ class DeletionTests(TestCase):
s2 = S.objects.create(pk=2, r=r) s2 = S.objects.create(pk=2, r=r)
T.objects.create(pk=1, s=s1) T.objects.create(pk=1, s=s1)
T.objects.create(pk=2, s=s2) T.objects.create(pk=2, s=s2)
RChild.objects.create(r_ptr=r)
r.delete() r.delete()
self.assertEqual( self.assertEqual(
pre_delete_order, [(T, 2), (T, 1), (S, 2), (S, 1), (R, 1)] pre_delete_order, [(T, 2), (T, 1), (RChild, 1), (S, 2), (S, 1), (R, 1)]
) )
self.assertEqual( self.assertEqual(
post_delete_order, [(T, 1), (T, 2), (S, 1), (S, 2), (R, 1)] post_delete_order, [(T, 1), (T, 2), (RChild, 1), (S, 1), (S, 2), (R, 1)]
) )
models.signals.post_delete.disconnect(log_post_delete) models.signals.post_delete.disconnect(log_post_delete)