Signal inconsistency between auto_created and manually defined intermediate models for m2m fields
|Reported by:||gsakkis||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/clear sends 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/remove are 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.
Change History (6)
comment:1 Changed 4 years ago by gsakkis
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset