[Django] #36264: keep_parents=True does not exclude proxy neighbors

16 views
Skip to first unread message

Django

unread,
Mar 19, 2025, 3:28:29 AMMar 19
to django-...@googlegroups.com
#36264: keep_parents=True does not exclude proxy neighbors
-------------------------------------+-------------------------------------
Reporter: Vladimir | Type: Bug
Status: new | Component: Database
| layer (models, ORM)
Version: 5.1 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
{{{
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`
--
Ticket URL: <https://code.djangoproject.com/ticket/36264>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 19, 2025, 5:14:58 AMMar 19
to django-...@googlegroups.com
#36264: keep_parents=True does not exclude proxy neighbors
-------------------------------------+-------------------------------------
Reporter: Vladimir | Owner: (none)
Type: Bug | Status: closed
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* resolution: => invalid
* status: new => closed

Comment:

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 foo
}}}
So the parent is kept. That the `BazItem` is deleted is due to the
`CASCADE` delete. To me, this looks like it's by design.
--
Ticket URL: <https://code.djangoproject.com/ticket/36264#comment:1>

Django

unread,
Mar 19, 2025, 6:20:25 AMMar 19
to django-...@googlegroups.com
#36264: keep_parents=True does not exclude proxy neighbors
-------------------------------------+-------------------------------------
Reporter: Vladimir | Owner: (none)
Type: Bug | Status: closed
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Vladimir):

Replying to [comment:1 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 foo
> }}}
> So the parent is kept. That the `BazItem` is deleted is due to the
`CASCADE` 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
--
Ticket URL: <https://code.djangoproject.com/ticket/36264#comment:2>

Django

unread,
Mar 19, 2025, 7:12:24 AMMar 19
to django-...@googlegroups.com
#36264: keep_parents=True does not exclude proxy neighbors
-------------------------------------+-------------------------------------
Reporter: Vladimir | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Vladimir):

* resolution: invalid =>
* status: closed => new

--
Ticket URL: <https://code.djangoproject.com/ticket/36264#comment:3>

Django

unread,
Mar 19, 2025, 8:19:38 AMMar 19
to django-...@googlegroups.com
#36264: keep_parents=True does not exclude proxy neighbors
-------------------------------------+-------------------------------------
Reporter: Vladimir | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Unreviewed => Accepted

Comment:

Apologies, I read it wrong and thought `Baz` inherited from `Bar`.
I can replicate, I agree this is a bug
--
Ticket URL: <https://code.djangoproject.com/ticket/36264#comment:4>

Django

unread,
Mar 19, 2025, 12:17:54 PMMar 19
to django-...@googlegroups.com
#36264: keep_parents=True does not exclude proxy neighbors
-------------------------------------+-------------------------------------
Reporter: Vladimir | Owner:
| JakeWalson
Type: Bug | Status: assigned
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by JakeWalson):

* owner: (none) => JakeWalson
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36264#comment:5>

Django

unread,
Aug 30, 2025, 10:14:15 AMAug 30
to django-...@googlegroups.com
#36264: keep_parents=True does not exclude proxy neighbors
-------------------------------------+-------------------------------------
Reporter: Vladimir | Owner:
| JaeHyuckSa
Type: Bug | Status: assigned
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by JaeHyuckSa):

* owner: JakeWalson => JaeHyuckSa

--
Ticket URL: <https://code.djangoproject.com/ticket/36264#comment:6>

Django

unread,
Aug 30, 2025, 10:15:28 AMAug 30
to django-...@googlegroups.com
#36264: keep_parents=True does not exclude proxy neighbors
-------------------------------------+-------------------------------------
Reporter: Vladimir | Owner:
| JaeHyuckSa
Type: Bug | Status: assigned
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by JaeHyuckSa):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36264#comment:7>

Django

unread,
Sep 1, 2025, 9:41:39 PMSep 1
to django-...@googlegroups.com
#36264: keep_parents=True does not exclude proxy neighbors
-------------------------------------+-------------------------------------
Reporter: Vladimir | Owner:
| JaeHyuckSa
Type: Bug | Status: assigned
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36264#comment:8>

Django

unread,
Sep 2, 2025, 1:01:41 AMSep 2
to django-...@googlegroups.com
#36264: keep_parents=True does not exclude proxy neighbors
-------------------------------------+-------------------------------------
Reporter: Vladimir | Owner:
| JaeHyuckSa
Type: Bug | Status: assigned
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by JaeHyuckSa):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/36264#comment:9>

Django

unread,
Sep 22, 2025, 5:07:54 AMSep 22
to django-...@googlegroups.com
#36264: keep_parents=True does not exclude proxy neighbors
-------------------------------------+-------------------------------------
Reporter: Vladimir | Owner:
| JaeHyuckSa
Type: Bug | Status: assigned
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/36264#comment:10>

Django

unread,
Sep 23, 2025, 10:41:10 AMSep 23
to django-...@googlegroups.com
#36264: keep_parents=True does not exclude proxy neighbors
-------------------------------------+-------------------------------------
Reporter: Vladimir | Owner:
| JaeHyuckSa
Type: Bug | Status: closed
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"748551fea0b4e37231203a063356572a47e09efb" 748551f]:
{{{#!CommitTicketReference repository=""
revision="748551fea0b4e37231203a063356572a47e09efb"
Fixed #36264 -- Excluded proxy neighbors of parents from deletion
collection when keep_parents=True.

Signed-off-by: saJaeHyukc <wogur...@gmail.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36264#comment:11>

Django

unread,
Sep 23, 2025, 10:47:06 AMSep 23
to django-...@googlegroups.com
#36264: keep_parents=True does not exclude proxy neighbors
-------------------------------------+-------------------------------------
Reporter: Vladimir | Owner:
| JaeHyuckSa
Type: Bug | Status: closed
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"e0f328d790539868252cea10cf40e620b9aecd31" e0f328d7]:
{{{#!CommitTicketReference repository=""
revision="e0f328d790539868252cea10cf40e620b9aecd31"
[6.0.x] Fixed #36264 -- Excluded proxy neighbors of parents from deletion
collection when keep_parents=True.

Signed-off-by: saJaeHyukc <wogur...@gmail.com>

Backport of 748551fea0b4e37231203a063356572a47e09efb from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36264#comment:12>
Reply all
Reply to author
Forward
0 new messages