#29615: post_remove action is called even though there's no relation
--------------------------------------+------------------------------------
Reporter: nirmalraghavan | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 2.0
Severity: Normal | Resolution:
Keywords: signals, m2m_changed | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Carlton Gibson):
* keywords: => signals, m2m_changed
* component: Database layer (models, ORM) => Documentation
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted
Comment:
OK, this is distinct from #22296.
There is an anomaly here.
[https://github.com/django/django/blob/4198445afcba94eb7a25b50c96ec6c2694ed2192/django/db/models/fields/related_descriptors.py#L1069-L1075
`add()` calls filter out the existing instances before processing the
ids]:
{{{
vals = (self.through._default_manager.using(db)
.values_list(target_field_name, flat=True)
.filter(**{
source_field_name: self.related_val[0],
'%s__in' % target_field_name: new_ids,
}))
new_ids.difference_update(vals)
}}}
This is necessary to avoid `django.db.utils.IntegrityError: UNIQUE
constraint failed ...` errors.
No such problem exists with duplicate `delete()` calls, so no such
filtering is done.
I'm guessing that the extra DB query would **not** be considered worth it
to avoid the extra signal call here. (Anyone?)
But I think this probably could be documented as a note at the end of the
[https://github.com/django/django/blob/4198445afcba94eb7a25b50c96ec6c2694ed2192/docs/ref/signals.txt#L208
`m2m_changed` reference].
--
Ticket URL: <https://code.djangoproject.com/ticket/29615#comment:2>
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/072.501b5325b77279330dd8bafa1ccc9144%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.