mirror of
https://github.com/django/django.git
synced 2025-09-24 23:49:12 +00:00
Fixed #36264 -- Excluded proxy neighbors of parents from deletion collection when keep_parents=True.
Signed-off-by: saJaeHyukc <wogur981208@gmail.com>
This commit is contained in:
parent
efb96138b4
commit
748551fea0
@ -309,7 +309,10 @@ class Collector:
|
||||
protected_objects = defaultdict(list)
|
||||
for related in get_candidate_relations_to_delete(model._meta):
|
||||
# Preserve parent reverse relationships if keep_parents=True.
|
||||
if keep_parents and related.model in model._meta.all_parents:
|
||||
if (
|
||||
keep_parents
|
||||
and related.model._meta.concrete_model in model._meta.all_parents
|
||||
):
|
||||
continue
|
||||
field = related.field
|
||||
on_delete = field.remote_field.on_delete
|
||||
|
@ -32,6 +32,11 @@ class RChild(R):
|
||||
pass
|
||||
|
||||
|
||||
class RProxy(R):
|
||||
class Meta:
|
||||
proxy = True
|
||||
|
||||
|
||||
class RChildChild(RChild):
|
||||
pass
|
||||
|
||||
@ -179,7 +184,7 @@ class RelToBase(models.Model):
|
||||
|
||||
|
||||
class Origin(models.Model):
|
||||
pass
|
||||
r_proxy = models.ForeignKey("RProxy", models.CASCADE, null=True)
|
||||
|
||||
|
||||
class Referrer(models.Model):
|
||||
|
@ -34,6 +34,7 @@ from .models import (
|
||||
RChild,
|
||||
RChildChild,
|
||||
Referrer,
|
||||
RProxy,
|
||||
S,
|
||||
T,
|
||||
User,
|
||||
@ -675,6 +676,14 @@ class DeletionTests(TestCase):
|
||||
)
|
||||
signal.disconnect(receiver, sender=Referrer)
|
||||
|
||||
def test_keep_parents_does_not_delete_proxy_related(self):
|
||||
r_child = RChild.objects.create()
|
||||
r_proxy = RProxy.objects.get(pk=r_child.pk)
|
||||
Origin.objects.create(r_proxy=r_proxy)
|
||||
self.assertEqual(Origin.objects.count(), 1)
|
||||
r_child.delete(keep_parents=True)
|
||||
self.assertEqual(Origin.objects.count(), 1)
|
||||
|
||||
|
||||
class FastDeleteTests(TestCase):
|
||||
def test_fast_delete_all(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user