Opened 16 years ago
Closed 16 years ago
#10304 closed (invalid)
topics/db/queries.txt about delete() lies!
Reported by: | Marc Fargas | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.0 |
Severity: | Keywords: | delete | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
queries.txt says:
Keep in mind that this will, whenever possible, be executed purely in SQL, and so the ``delete()`` methods of individual object instances will not necessarily be called during the process.
Given how delete() is implemented in QuerySet one would say it's almost impossible to avoid calling the delete() of every object (to not say it does lots of things).
Option a would be to fix the docs, but current behaviour makes it almost impossible to delete large querysets without recurring to manual SQL (And dealing with QS cache, etc later). So this may have to be fixed in some way, or a workaround documented.
Note:
See TracTickets
for help on using tickets.
I haven't looked at the QuerySet code but a little shell experimentation shows that it is not impossible to avoid calling delete() of every single object. Given this model:
and this shell session:
The individual delete() method was not called for
DT.objects.all().delete()
.(Even if it was the case that the code as written now always guaranteed the individual delete() methods were called, the doc would not be wrong. It is warning that the individual delete() may not be called when objects are deleted in bulk, it doesn't say it absolutely will not be called.)