Opened 5 years ago
Closed 5 years ago
#31454 closed Cleanup/optimization (duplicate)
The behavior of m2m_changed signals does not match the documentation.
Reported by: | Konstantin Yegupov | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 3.0 |
Severity: | Normal | Keywords: | signal, m2m_changed |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Found in v2.2.11, still appears to be valid for the master version.
The documentation at https://docs.djangoproject.com/en/3.0/ref/signals/ says:
"pre_add"
Sent before one or more objects are added to the relation.
But, in fact, pre_add is sent even if *zero* objects are added to the relation (because all the objects to be added already exist in the database).
The pk_set argument will be empty, but the signal will still fire.
The same applies to post_add, pre_remove, post_remove "actions".
Either the documentation needs to be corrected to explain that pk_set might be empty, or the code in related_descriptors.py should not fire the signals when missing_target_ids / old_ids is empty.
Change History (1)
comment:1 by , 5 years ago
Component: | Database layer (models, ORM) → Documentation |
---|---|
Resolution: | → duplicate |
Status: | new → closed |
Summary: | The behavior of m2m_changed signals does not match the documentation → The behavior of m2m_changed signals does not match the documentation. |
Type: | Uncategorized → Cleanup/optimization |
It's already documented that:
IMO it's sufficient, if all PKs already exist then it's empty. I don't think that an explicit note that it may be empty changes anything.
Duplicate of #27462.