[Django] #27407: The delete(keep_parents=True) option should preserve parent reverse relationships.

10 views
Skip to first unread message

Django

unread,
Oct 30, 2016, 11:20:28 PM10/30/16
to django-...@googlegroups.com
#27407: The delete(keep_parents=True) option should preserve parent reverse
relationships.
-------------------------------------+-------------------------------------
Reporter: Simon | Owner: nobody
Charette |
Type: Bug | Status: new
Component: Database | Version: master
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The `keep_parent` option of `Model.delete()` is
[https://docs.djangoproject.com/en/1.10/ref/models/instances/#django.db.models.Model.delete
documented to keep the parent model’s data] but actually only preserves
the child-parent relationship and will discard the parent reverse
relationships which can lead to unexpected data loss.

{{{#!python
class Place(models.Model):
pass

class Restaurant(Place):
pass

class Event(models.Model):
location = models.ForeignKey(Place, related_name='events')

>> restaurant = Restaurant.objects.create()
>> place = restaurant.parent_ptr
>> Events.objects.create(location=place)
>> place.events.count()
1
>> restaurant.delete(keep_parents=True)
>> place.events.count()
0
}}}

I believe that users of the `keep_parents` option would expect
relationships pointing to their ''kept'' parents to also be preserved as
they were not deleted and following the `CASCADE` chain just doesn't make
sense here.

If this had been discovered during the 1.9.x life cycle this could have
qualified for a potential data loss backport but I'm not sure what should
be done at this point.

The `keep_parents` option was added in
81c2d9f60b9206c1291e5b1c3c8686f24a7726e1 to fix the long standing #15579.

--
Ticket URL: <https://code.djangoproject.com/ticket/27407>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 1, 2016, 4:32:05 PM11/1/16
to django-...@googlegroups.com
#27407: The delete(keep_parents=True) option should preserve parent reverse
relationships.
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(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 Tim Graham):

* stage: Unreviewed => Accepted


Comment:

1.9.x still qualifies for data loss fixes, though I'm not sure it's
critical since no one noticed it until now. Fine with me for at least
1.10.x.

--
Ticket URL: <https://code.djangoproject.com/ticket/27407#comment:1>

Django

unread,
Nov 1, 2016, 4:32:51 PM11/1/16
to django-...@googlegroups.com
#27407: Model.delete(keep_parents=True) should preserve parent reverse
relationships

-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: master
(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
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/27407#comment:2>

Django

unread,
Nov 14, 2016, 8:17:37 PM11/14/16
to django-...@googlegroups.com
#27407: Model.delete(keep_parents=True) should preserve parent reverse
relationships
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9

(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 Simon Charette):

* has_patch: 0 => 1
* version: master => 1.9


Comment:

[https://github.com/django/django/pull/7557 PR]

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

Django

unread,
Nov 15, 2016, 8:50:40 AM11/15/16
to django-...@googlegroups.com
#27407: Model.delete(keep_parents=True) should preserve parent reverse
relationships
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 1.9
(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 Tim Graham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/27407#comment:4>

Django

unread,
Nov 15, 2016, 8:39:05 PM11/15/16
to django-...@googlegroups.com
#27407: Model.delete(keep_parents=True) should preserve parent reverse
relationships
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.9
(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 Simon Charette <charette.s@…>):

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


Comment:

In [changeset:"31a56e30cfb3c8e1a9373e5abdd12b5b23d5d910" 31a56e30]:
{{{
#!CommitTicketReference repository=""
revision="31a56e30cfb3c8e1a9373e5abdd12b5b23d5d910"
Fixed #27407 -- Made Model.delete(keep_parents=True) preserve parent
reverse relationships.

Thanks Tim for the review.
}}}

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

Django

unread,
Nov 15, 2016, 8:51:25 PM11/15/16
to django-...@googlegroups.com
#27407: Model.delete(keep_parents=True) should preserve parent reverse
relationships
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 1.9
(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 Simon Charette <charette.s@…>):

In [changeset:"b495d8e334c2487eef6282bac5dd0c1f43da71ef" b495d8e3]:
{{{
#!CommitTicketReference repository=""
revision="b495d8e334c2487eef6282bac5dd0c1f43da71ef"
[1.10.x] Fixed #27407 -- Made Model.delete(keep_parents=True) preserve
parent reverse relationships.

Thanks Tim for the review.

Backport of 31a56e30cfb3c8e1a9373e5abdd12b5b23d5d910 from master
}}}

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

Reply all
Reply to author
Forward
0 new messages