#31981: many_to_many add() does not trigger post_save signal for the through class -----------------------------------------+------------------------ Reporter: Kurt Wheeler | Owner: nobody Type: Uncategorized | Status: new Component: Uncategorized | Version: 3.1 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | -----------------------------------------+------------------------ I have a many-to-many relationship on my organization model: https://github.com/AlexsLemonade/resources- portal/blob/dev/api/resources_portal/models/organization.py#L50. As you can see, I specify `through="OrganizationUserAssociation"`, and that class is defined here: https://github.com/AlexsLemonade/resources- portal/blob/dev/api/resources_portal/models/associations/organization_user_association.py
In a branch I am working on, I am adding a post-save signal to OrganizationUserAssociation. What I have found is that this isn't called when `organization.members.add(user)` is called. I can't actually tell if this is a bug or just poorly documented. The only documentation I can find for the add() method is here: https://docs.djangoproject.com/en/3.1/topics/db/examples/many_to_many/ and it only shows the method being used for a single object. I think the post_save signal isn't being triggered because add() is doing a bulk update instead of creating the through class and saving that? Does add() handle multiple objects, is that why bulk update is being used? I can't actually find any documentation that indicates either way. However, it makes sense to me that if add() is called with a single object, and there is a `through` class for the many-to-many field, then the `through` class should be used to create the relationship. It seems like now I have to go through my code and find everywhere I called add() and do it the less convenient way. (The unfortunate thing is, that add() isn't that much more convenient than creating the association, so I wish I had just been warned so I could avoid it altogether.) -- Ticket URL: <https://code.djangoproject.com/ticket/31981> 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 django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/054.43a464511f65a754ce4cb99fbb0a7309%40djangoproject.com.