Opened 17 years ago

Closed 17 years ago

#3081 closed defect (fixed)

[patch] Fix deleting objects with generic relation

Reported by: Alex Dedul Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When you have generic relation in a model and you do model_obj.delete() from generic related table deleted all records with object_id = model_obj.id - that is incorrect. Correct condition for deletion should be "object_id = model_obj.id AND content_type = content_type(model_obj)" (in pseudo code). Also this patch fixes deletion of a model with generic foreign key(i.e. model referenced by generic relation) - current behavior is to try to delete records from m2m generic relations, but there is no m2m tables created for generic relations so there is no need to delete anything in this case - this also fixes issues mentioned in #2749 with deletion of both records.

Attached patch fixes all these issues.

Attachments (1)

genericrelation_delete.patch (3.0 KB ) - added by Alex Dedul 17 years ago.

Download all attachments as: .zip

Change History (3)

by Alex Dedul, 17 years ago

comment:1 by Adrian Holovaty, 17 years ago

Component: Core frameworkDatabase wrapper

comment:2 by Russell Keith-Magee, 17 years ago

Resolution: fixed
Status: newclosed

(In [4428]) Fixed #3215, #3081, #2749 -- Fixed problem with mistaken deletion of objects when a GenericRelation? is involved. Thanks to Thomas Steinacher for helping to narrow down the problem (#3215), and Alex Dedul (#3081) for the starting point of a working patch.

Note: See TracTickets for help on using tickets.
Back to Top