Opened 4 years ago

Last modified 4 years ago

#22296 new Bug

m2m_changed pk_set value inconsistent between post_add and post_remove

Reported by: anentropic Owned by: nobody
Component: Database layer (models, ORM) Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


the docs say:

"pk_set: For the pre_add, post_add, pre_remove and post_remove actions, this is a set of primary key values that have been added to or removed from the relation."

What I found is that for action=='post_add':

  • first time add(x) -> set([x])
  • next time (same x) add(x) -> set([])

but for action=='post_remove':

  • first time remove(x) -> set([x])
  • next time (same x) remove(x) -> set([x])

I feel like they should be consistent. Either way is fine but the behaviour of post_add seems more useful to me (can avoid unnecessary action in your signal receiver)... but it should be documented that you get empty set if nothing needed adding.

I've only tried on 1.5 so far but looking at source I don't see any new code to change this behaviour

Whereas it looks like the add method has code to deliberately exclude already added items

I'm happy to make a patch if it's felt this is useful?

Change History (2)

comment:1 Changed 4 years ago by anentropic

Summary: Documentation clarification: m2m_changed pk_set inconsistent between post_add and post_removem2m_changed pk_set value inconsistent between post_add and post_remove

comment:2 Changed 4 years ago by Aymeric Augustin

Component: UncategorizedDatabase layer (models, ORM)
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug
Note: See TracTickets for help on using tickets.
Back to Top