#30287: post_remove and post_add behave differently for m2m_changed
------------------------------------------+-------------------------
               Reporter:  nirmalraghavan  |          Owner:  nobody
                   Type:  Uncategorized   |         Status:  new
              Component:  Uncategorized   |        Version:  2.1
               Severity:  Normal          |       Keywords:  signals
           Triage Stage:  Unreviewed      |      Has patch:  0
    Needs documentation:  0               |    Needs tests:  0
Patch needs improvement:  0               |  Easy pickings:  0
                  UI/UX:  0               |
------------------------------------------+-------------------------
 Consider the following Model,


 {{{
 class MyModel(models.Model):
     likes = models.ForeignKey(User)
 }}}


 Now if I add a user to the likes field as below,

 {{{
 myObj.likes.add(user)
 }}}


 my m2m_changed receiver method will be called in signals module with
 action post_add and pk_set as the User ID. If I try to add likes again
 with the same user and same above method, now post_add again called with
 pk_set as empty.

 And when I try to remove the user as below,

 {{{
 myObj.likes.remove(user)
 }}}


 m2m_changed receiver method is called with action post_remove and pk_set
 as User ID. And if I try to remove the same user again, this time also
 m2m_changed receiver method is called. But this time pk_set contains the
 User ID.

 For post_add, pk_set will be empty after first add. Subsequent calls will
 always set pk_set as empty. But for post_remove pk_set will always
 contains pk_set value. Why it is that?

 I'm calculating points based on this like events. Now I need to make sure
 ManyToMany relationship exist before adding/substracting points by making
 an extra call to database. If somehow we could know if the relation
 already added/removed from m2m_changed signal, it will be great.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30287>
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/057.f2d8aed8b7b7f9c584e1b8a768caaf77%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to