Opened 14 years ago

Closed 14 years ago

Last modified 13 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: no UI/UX: no

Description

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

A rough models.py 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.save()
>>> 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 by Russell Keith-Magee, 14 years ago

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 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

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