#36264 closed Bug (fixed)
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: | Ready for checkin | |
| 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 (12)
follow-up: 2 comment:1 by , 8 months ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
comment:2 by , 8 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
BazItemis deleted is due to theCASCADEdelete. 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 , 8 months ago
| Resolution: | invalid |
|---|---|
| Status: | closed → new |
comment:4 by , 8 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 , 8 months ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:6 by , 3 months ago
| Owner: | changed from to |
|---|
comment:7 by , 3 months ago
| Has patch: | set |
|---|
comment:8 by , 2 months ago
| Patch needs improvement: | set |
|---|
comment:9 by , 2 months ago
| Patch needs improvement: | unset |
|---|
comment:10 by , 8 weeks ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
I'm not 100% sure what you're trying to show here:
So the parent is kept. That the
BazItemis deleted is due to theCASCADEdelete. To me, this looks like it's by design.