From 4e1d809aa570c0e0736587672607f9d6c22e42c9 Mon Sep 17 00:00:00 2001 From: Daniel Izquierdo Date: Tue, 22 Oct 2019 09:47:18 +0200 Subject: [PATCH] Refs #27272 -- Added Collector.add_dependency(). --- django/db/models/deletion.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/django/db/models/deletion.py b/django/db/models/deletion.py index 62afff1f50..3ad9ca0b35 100644 --- a/django/db/models/deletion.py +++ b/django/db/models/deletion.py @@ -102,11 +102,15 @@ class Collector: # deleting, and therefore do not affect the order in which objects have # to be deleted. if source is not None and not nullable: - if reverse_dependency: - source, model = model, source - self.dependencies[source._meta.concrete_model].add(model._meta.concrete_model) + self.add_dependency(source, model, reverse_dependency=reverse_dependency) return new_objs + def add_dependency(self, model, dependency, reverse_dependency=False): + if reverse_dependency: + model, dependency = dependency, model + self.dependencies[model._meta.concrete_model].add(dependency._meta.concrete_model) + self.data.setdefault(dependency, self.data.default_factory()) + def add_field_update(self, field, value, objs): """ Schedule a field update. 'objs' must be a homogeneous iterable