Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#13534 closed (invalid)

m2m_changed signal doesn't call receiver

Reported by: Chris Targett <chris@…> Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2-beta
Severity: Keywords: m2m_save, dispatch, signal
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


For some reason or another the m2m_changed signal does not call the receiver.

A rough similar to my code:

class SomeContent(models.Model):
  sites = models.ForeignKey(Site)

def m2m_handler(sender, instance, action, reverse, model, pk_set, **kwargs):
  raise NotImplementedError
models.signals.m2m_changed.connect(m2m_handler, SomeContent)

>>> sc = SomeContent()
>>> sc.sites.add(Site.objects.get_current()) # Here you would expect a "NotImplementedError"

It seems the signal loses all receivers in django.dispatch.dispatcher.Signal._line_receivers line 215.

Change History (2)

comment:1 Changed 8 years ago by Russell Keith-Magee

Resolution: invalid
Status: newclosed

The sample code is invalid on two counts:

1) The relationship isn't a m2m, so of course it doesn't emit an m2m signal
2) The sender of a m2m signal is bound to the through model, not the model defining the relationship. Assuming the key to Site was a m2m, you would need to connect:

models.signals.m2m_changed.connect(m2m_handler, SomeContent.sites.through)

comment:2 Changed 7 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top