diff options
| author | mgaligniana <marcelogaligniana@gmail.com> | 2021-12-27 23:32:07 -0300 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-01-11 08:06:18 +0100 |
| commit | fa235004dd1423b129befe847bbf207808ca07ad (patch) | |
| tree | ef9f65f34fbd031007dc2986916ac3927a645698 /django | |
| parent | f1905db6c0004a2b6c8b69c55a1f5f9da58ce2eb (diff) | |
Fixed #13251 -- Made pre/post_delete signals dispatch the origin.
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/admin/utils.py | 2 | ||||
| -rw-r--r-- | django/contrib/contenttypes/management/commands/remove_stale_contenttypes.py | 2 | ||||
| -rw-r--r-- | django/db/models/base.py | 2 | ||||
| -rw-r--r-- | django/db/models/deletion.py | 10 | ||||
| -rw-r--r-- | django/db/models/query.py | 2 |
5 files changed, 11 insertions, 7 deletions
diff --git a/django/contrib/admin/utils.py b/django/contrib/admin/utils.py index 42d0d96ea6..4e3d025a56 100644 --- a/django/contrib/admin/utils.py +++ b/django/contrib/admin/utils.py @@ -116,7 +116,7 @@ def get_deleted_objects(objs, request, admin_site): return [], {}, set(), [] else: using = router.db_for_write(obj._meta.model) - collector = NestedObjects(using=using) + collector = NestedObjects(using=using, origin=objs) collector.collect(objs) perms_needed = set() diff --git a/django/contrib/contenttypes/management/commands/remove_stale_contenttypes.py b/django/contrib/contenttypes/management/commands/remove_stale_contenttypes.py index e2856bb0f7..5593ecb469 100644 --- a/django/contrib/contenttypes/management/commands/remove_stale_contenttypes.py +++ b/django/contrib/contenttypes/management/commands/remove_stale_contenttypes.py @@ -51,7 +51,7 @@ class Command(BaseCommand): ct_info = [] for ct in to_remove: ct_info.append(' - Content type for %s.%s' % (ct.app_label, ct.model)) - collector = NoFastDeleteCollector(using=using) + collector = NoFastDeleteCollector(using=using, origin=ct) collector.collect([ct]) for obj_type, objs in collector.data.items(): diff --git a/django/db/models/base.py b/django/db/models/base.py index 0d50dad0c9..793cd936f1 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -987,7 +987,7 @@ class Model(metaclass=ModelBase): "to None." % (self._meta.object_name, self._meta.pk.attname) ) using = using or router.db_for_write(self.__class__, instance=self) - collector = Collector(using=using) + collector = Collector(using=using, origin=self) collector.collect([self], keep_parents=keep_parents) return collector.delete() diff --git a/django/db/models/deletion.py b/django/db/models/deletion.py index d8d8b25990..b99337a309 100644 --- a/django/db/models/deletion.py +++ b/django/db/models/deletion.py @@ -76,8 +76,10 @@ def get_candidate_relations_to_delete(opts): class Collector: - def __init__(self, using): + def __init__(self, using, origin=None): self.using = using + # A Model or QuerySet object. + self.origin = origin # Initially, {model: {instances}}, later values become lists. self.data = defaultdict(set) # {model: {(field, value): {instances}}} @@ -404,7 +406,8 @@ class Collector: for model, obj in self.instances_with_model(): if not model._meta.auto_created: signals.pre_delete.send( - sender=model, instance=obj, using=self.using + sender=model, instance=obj, using=self.using, + origin=self.origin, ) # fast deletes @@ -435,7 +438,8 @@ class Collector: if not model._meta.auto_created: for obj in instances: signals.post_delete.send( - sender=model, instance=obj, using=self.using + sender=model, instance=obj, using=self.using, + origin=self.origin, ) # update collected instances diff --git a/django/db/models/query.py b/django/db/models/query.py index fb6639793a..86b1631f67 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -753,7 +753,7 @@ class QuerySet: del_query.query.select_related = False del_query.query.clear_ordering(force=True) - collector = Collector(using=del_query.db) + collector = Collector(using=del_query.db, origin=self) collector.collect(del_query) deleted, _rows_count = collector.delete() |
