#17688: No m2m_changed signal sent to when referenced object is deleted
-------------------------------------+-------------------------------------
Reporter: jblaine@… | Owner:
| jorgecarleitao
Type: Bug | Status: assigned
Component: Database layer | Version: 1.3
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Adam Wróbel):
In terms of SQL operations when you delete a referenced object you have
to:
1. Delete the rows from m2m association table to loosen up foreign
constraints
2. Delete the object's row itself
I think this should work the same on the Django side, i.e.:
1. remove the object from m2m set just as you would normally (sending all
the usual notifications)
2. delete the referenced object
@jorgecarleitao has created two new event labels – "pre_delete" and
"post_delete" – but I think they are redundant and we should reuse
"pre_remove" and "post_remove" that we trigger when item is simply removed
from the relation.
Pizza has a set of toppings. Before a topping is deleted it is removed
from all the pizzas. Probably in 99% cases the pizza will not care whether
the topping has been entirely deleted from the store or just removed from
this particular pizza.
Having this new, special event names would complicate code in every
m2m_changed hook. We just want to do something about the pizza now that
this topping is no longer on it: maybe update its price.
In either case the order of events should be:
- send "pre" hook
- delete rows from m2m table
- send "post" hook
- delete the related model
The reason for having "post" hook in between these two SQL DELETEs is is
that user might want to access the related model using its ID inside this
callback, e.g. check the price of the topping before adjusting the price
of the pizza. Just as when the item is simply removed from relation you
could still query it from DB in both hooks.
--
Ticket URL: <https://code.djangoproject.com/ticket/17688#comment:16>
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/078.981c8e4d057597bc13c42de1dc6081fb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.