Opened 6 months ago
Last modified 3 days ago
#36264 assigned Bug
keep_parents=True does not exclude proxy neighbors
Reported by: | Vladimir | Owned by: | JaeHyuckSa |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 5.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
class Foo(Model): pass class Bar(Foo): pass class Baz(Foo): class Meta: proxy = True class BazItem(Model): baz = ForeignKey(to=Baz, on_delete=CASCADE) ... bar = Bar.objects.create() baz = Baz.objects.all().first() BazItem.objects.create(baz=baz) assert BazItem.objects.all().count() == 1 bar.delete(keep_parents=True) assert BazItem.objects.all().count() == 0
seems django.db.models.deletion.Collector.collect
if keep_parents and related.model in model._meta.all_parents: continue
should use concrete_model
Change History (9)
follow-up: 2 comment:1 by , 6 months ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 6 months ago
Replying to Sarah Boyce:
I'm not 100% sure what you're trying to show here:
foo_parent = bar.foo_ptr bar.delete(keep_parents=True) foo_parent.refresh_from_db() assert fooSo the parent is kept. That the
BazItem
is deleted is due to theCASCADE
delete. To me, this looks like it's by design.
BazItem
referencing to Baz
(Foo
table), and deleting bar
instance with keep_parents=True
should delete only Bar
table row, but delete BazItem
too
If the Baz
model also uses table inheritance, deleting bar
with keep_parents=True
will not affect the BazItem
table. Regardless of where the BazItem
will refer to, Foo
or Baz
comment:3 by , 6 months ago
Resolution: | invalid |
---|---|
Status: | closed → new |
comment:4 by , 6 months ago
Triage Stage: | Unreviewed → Accepted |
---|
Apologies, I read it wrong and thought Baz
inherited from Bar
.
I can replicate, I agree this is a bug
comment:5 by , 6 months ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:6 by , 6 days ago
Owner: | changed from | to
---|
comment:7 by , 6 days ago
Has patch: | set |
---|
comment:8 by , 3 days ago
Patch needs improvement: | set |
---|
comment:9 by , 3 days ago
Patch needs improvement: | unset |
---|
I'm not 100% sure what you're trying to show here:
So the parent is kept. That the
BazItem
is deleted is due to theCASCADE
delete. To me, this looks like it's by design.