Signal inconsistency between auto_created and manually defined intermediate models for m2m fields
|Reported by:||George Sakkis||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.2|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
In Django 1.2 the the signal handling for m2m fields differs based on whether the intermediate model is auto_created or defined manually. As per http://groups.google.com/group/django-developers/msg/2aa826b200e60294:
- For m2m fields with auto_created intermediate model, calling
Model.m2m_field.add/remove/clearsends m2m_changed. However adding/removing relations using directly the through model (e.g.
Model.m2m_field.through.objects.create(...)) does not send m2m_changed. Adding handlers for pre/post_save, pre/post_delete on the through model has no effect; the code specifically checks for auto_created models and does not send these signals in this case.
- For m2m fields with a given intermediate model,
Model.m2m_field.add/removeare not exposed (at least for now but this may change, see #9475) and therefore m2m_changed is not sent; instead you have to handle addition/removal in pre/post_save, pre/post_delete handlers on the through model. However
Model.m2m_field.clear()is exposed and does send m2m_changed; if there are pre/post_delete handlers on the through model, they are called as well after the m2m_changed.