m2m_changed fires before a clear but after add/remove
|Reported by:||rcatherman||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.2-beta|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
In db/models/fields/related.py I notice that _add_items and _remove_items perform the db actions and then fire the signal to the m2m_changed listeners. _clear_items fires the signal prior to the db interaction. The result is inconsistent. For my use case, I'd like to have my listener assert a relationship has at least one particular item no matter if it is accidentily cleared. It works on removal, but not on clear because I notice the DELETE happens after my re-INSERT.
I've made the change here and it works as expected now.