Opened 9 years ago

Closed 8 years ago

Last modified 5 years ago

#6915 closed (fixed)

object.some_set.all().delete() does not call the delete method on some object

Reported by: gert@… Owned by: nobody
Component: Documentation Version: master
Severity: Keywords: qsrf-cleanup delete
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by Ramiro Morales)

If you override an objects delete method:

object.something_set.all().delete()

does not do the same as:

for something in object.something_set.all():
    something.delete()

The new delete method is never called and hence any associated cleanup or audit code are never called. This comes to light when you delete an object which in turn deletes related objects.

Attachments (4)

6915.naive-patch.diff (755 bytes) - added by Johannes Dollinger 8 years ago.
6915.naive-patch.2.diff (2.2 KB) - added by Johannes Dollinger 8 years ago.
6915.regressiontest.diff (1.5 KB) - added by anonymous 8 years ago.
6915.naive.r7787.diff (3.7 KB) - added by Johannes Dollinger 8 years ago.

Download all attachments as: .zip

Change History (12)

Changed 8 years ago by Johannes Dollinger

Attachment: 6915.naive-patch.diff added

comment:1 Changed 8 years ago by Johannes Dollinger

Component: Core frameworkDatabase wrapper
Has patch: set
Needs documentation: set
Needs tests: unset
Patch needs improvement: set

Changed 8 years ago by Johannes Dollinger

Attachment: 6915.naive-patch.2.diff added

Changed 8 years ago by anonymous

Attachment: 6915.regressiontest.diff added

comment:2 Changed 8 years ago by Johannes Dollinger

Triage Stage: UnreviewedDesign decision needed

comment:3 Changed 8 years ago by anonymous

Keywords: qsrf-cleanup added

comment:4 Changed 8 years ago by Jacob

milestone: 1.0

comment:5 Changed 8 years ago by Ramiro Morales

Description: modified (diff)

Changed 8 years ago by Johannes Dollinger

Attachment: 6915.naive.r7787.diff added

comment:6 Changed 8 years ago by Malcolm Tredinnick

Component: Database wrapperDocumentation
Has patch: unset
Patch needs improvement: unset
Triage Stage: Design decision neededAccepted

This is only open until I (or somebody else) writes a documentation patch. The delete() method is primarily a mass-SQL operation, just like update(). However, because I suspect we sometimes do call delete() on some of the auxilliary objects, I'd like to try and document when that happens in case somebody does write a custom method. Really, though, there shouldn't be many custom delete() methods. Performing secondary actions for a delete is better done via post-delete signal handlers. Calling the delete() method on every object that has one will just slow things down.

So the resolution here is a docs patch, nothing more.

comment:7 Changed 8 years ago by James Bennett

Resolution: fixed
Status: newclosed

(In [8406]) Fixed #6915: Documented the fact that QuerySet.delete() may not call delete() methods of individual objects

comment:8 Changed 5 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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