0

I have a model that sends signal:

class WMTransaction(models.Model):
    def save(self, *args, **kwargs):
        if self.status == 'completed':
            self.completed = datetime.datetime.now()
            try:
                old = WMTransaction.objects.get(pk=self.pk)
                if old.status == 'processing':
                    print 'sending signal'
                    payment_done.send(self)
            except:
                pass
        super(WMTransaction, self).save(*args, **kwargs)

Also I have receivers in 2 modules:

@receiver(payment_done, dispatch_uid="make_this_signal_unique", weak=False)
def subscribe(sender, **kwargs):
    print 'subscribing'
    # processing

And:

@receiver(payment_done, dispatch_uid="this_signal_is_also_unique", weak=False)
def buy(sender, **kwargs):
    print 'buying'
    # processing

The problem is that subscribe function is called, and buy - isn't... Both modules are in installed apps, other functions from these modules work correctly. What's the problem with signals?

Kirill Bubochkin
  • 5,868
  • 2
  • 31
  • 50

1 Answers1

1

Has module_B been installed and the definition of buy actually gets executed? Check payment_done.receivers before the payment_done.send line.

okm
  • 23,575
  • 5
  • 83
  • 90
  • Yes, it appears that this definition isn't executed: payment_done.receivers prints `[(('make_this_signal_unique', 139659700131376), )]`. But why? Classes, defined in that file work normally. – Kirill Bubochkin Apr 08 '12 at 12:49
  • @ookami.kb well, what's the state of payment_done after `buy` definition? Is there any disconnect afterwards? – okm Apr 08 '12 at 13:53
  • BTW, what Python and env do you use? – okm Apr 08 '12 at 14:04
  • python 2.6, django 1.3. well I simply moved 2nd function to other modeule and it worked... so the problem was definitely in that module... – Kirill Bubochkin Apr 08 '12 at 14:30
  • @ookami.kb OK. Probably its because of weak=False, thread locking or importing ordering. If you figure out the reason later, I would like to know =) – okm Apr 08 '12 at 14:58
  • I don't think this is because of weak - I added it later, before that it didn't work either. I suspect I have a mistake somewhere with import... – Kirill Bubochkin Apr 08 '12 at 15:03