Re: [Django] #31981: many_to_many add() does not trigger post_save signal for the through class

2020-09-03 Thread Django
#31981: many_to_many add() does not trigger post_save signal for the through 
class
-+-
 Reporter:  Kurt Wheeler |Owner:  nobody
 Type:  Uncategorized|   Status:  closed
Component:  Database layer   |  Version:  3.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Kurt Wheeler):

 `add()` being a bulk operation isn't documented anywhere and all the
 examples I found in the docs showed it being used with a singular object.

-- 
Ticket URL: 
Django 
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/069.1f7148d580ec02ffe10d732ef15f6afa%40djangoproject.com.


Re: [Django] #31981: many_to_many add() does not trigger post_save signal for the through class

2020-09-03 Thread Django
#31981: many_to_many add() does not trigger post_save signal for the through 
class
-+-
 Reporter:  Kurt Wheeler |Owner:  nobody
 Type:  Uncategorized|   Status:  closed
Component:  Database layer   |  Version:  3.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by felixxm):

 * status:  new => closed
 * resolution:   => invalid
 * component:  Uncategorized => Database layer (models, ORM)


Comment:

 > 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.

 Yes because `.add()` doesn't call `save()` on
 `OrganizationUserAssociation` instances, this is a bulk operation. You
 should use the [https://docs.djangoproject.com/en/3.1/ref/signals/#m2m-
 changed m2m_changed] signal.

 Closing per TicketClosingReasons/UseSupportChannels.

-- 
Ticket URL: 
Django 
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/069.b8fad4452783d939076f1131679fe29a%40djangoproject.com.


[Django] #31981: many_to_many add() does not trigger post_save signal for the through class

2020-09-03 Thread Django
#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: 
Django 
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.