#21169: Deletion in custom reverse managers
-------------------------------------+-------------------------------------
     Reporter:  sebastian            |                    Owner:  loic84
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |               Resolution:
     Severity:  Release blocker      |             Triage Stage:  Accepted
     Keywords:                       |      Needs documentation:  1
    Has patch:  1                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------
Changes (by loic84):

 * needs_docs:  0 => 1
 * has_patch:  0 => 1


Comment:

 For the record I'm going to list all the changes and issues addressed by
 this ticket and #21174 since they are related.

 The culprits: the `clear()` and `remove()` methods of the M2M, FK, and GFK
 related managers, so six methods in total.

 Issues:

 - All methods except `FK.clear()` completely bypassed default filtering
 (i.e. custom `Manager.get_queryset()` with filters).
 - All methods except `FK.clear()` caused multiple consecutive db
 operations run without transaction. (see #21174)
 - Inconsistency between the implementation of `FK.remove()` and
 `FK.clear()`, in particular wrt emitted signals.
 - `M2M.clean()` and `M2M.remove()` were prone to race conditions for
 symmetrical relations. (see #comment:8)

 List of changes:

 - All methods now respect default filtering, which means you can't delete
 or change something that is filtered out.

 - All methods now run in a single query, which addresses all transaction
 concerns.

 - `FK.remove()` changed from successive `save()` calls, to a single
 `update()`.
     Gotcha: `pre_save` and `post_save` signals aren't fired anymore.

 - `M2M.remove()` and `M2M.clear()` rely on subqueries when filtering is
 involved.

 - Symmetrical `M2M.remove()` and `M2M.clear()` now run in a single query.

 - `GFK.remove()` and `GFK.clear()` now perform bulk delete.
     Gotcha: `Model.delete()` is not called anymore.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21169#comment:9>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.7ac83cf547bcd2c5880dc7a0dc83831f%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to