From 7862cbda86cdbced5fbfe4f0056105e657c1f92c Mon Sep 17 00:00:00 2001 From: Laura Feier Date: Wed, 4 Nov 2015 14:27:35 +0200 Subject: [PATCH] Fixed #24576 -- Made deletion of related objects deterministic. --- django/db/models/deletion.py | 2 +- tests/delete/tests.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/django/db/models/deletion.py b/django/db/models/deletion.py index 831e3c03db..1c3b7203b5 100644 --- a/django/db/models/deletion.py +++ b/django/db/models/deletion.py @@ -64,7 +64,7 @@ class Collector(object): def __init__(self, using): self.using = using # Initially, {model: {instances}}, later values become lists. - self.data = {} + self.data = OrderedDict() self.field_updates = {} # {model: {(field, value): {instances}}} # fast_deletes is a list of queryset-likes that can be deleted without # fetching the objects into memory. diff --git a/tests/delete/tests.py b/tests/delete/tests.py index 60c61ed281..9e383acb4e 100644 --- a/tests/delete/tests.py +++ b/tests/delete/tests.py @@ -224,12 +224,13 @@ class DeletionTests(TestCase): s2 = S.objects.create(pk=2, r=r) T.objects.create(pk=1, s=s1) T.objects.create(pk=2, s=s2) + RChild.objects.create(r_ptr=r) r.delete() 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( - 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)