#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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.fd8ef3e36f75fb053daaa4db17d7223a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.