﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30287	post_remove and post_add behave differently for m2m_changed	nirmalraghavan	nobody	"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."	Uncategorized	closed	Uncategorized	2.1	Normal	duplicate	signals		Unreviewed	0	0	0	0	0	0
