Django plugin app works with some Django signals but not others

I’m adding to an existing repo containing two Django plugin apps, both of which include properly-working Django signal receivers, as follows:

from django.core.signals import request_finished
from openedx.core.djangoapps.signals.signals import COURSE_GRADE_NOW_PASSED

@receiver(COURSE_GRADE_NOW_PASSED, dispatch_uid="i_am_unique")
def this_sparks_joy(sender, user, course_id, **kwargs):
  print("Marie Kondo cleaned the entry closet")

def this_also_sparks_joy(sender, **kwargs):
  print("Marie Kondo cleaned the pantry")

Oddly however, the following new Django signal that I’m trying to add does not work:

from common.lib.xmodule.xmodule.modulestore.django import SignalHandler

@receiver(SignalHandler.course_published, dispatch_uid="i_am_also_unique")
def this_does_not_spark_joy(sender, course_key, **kwargs):
  print("Marie Kondo does not clean this room for some reason")

I’ve confirmed that the signals themselves all load correctly via in both apps using the following pattern:

    def ready(self):
        Connect handlers to signals.
        from . import signals

I’ve also done diagnostics to verify that the @receiver decorator of the malfunctioning app at least recognizes the existence of the handler def, this_does_not_spark_joy(). the malfunctioning signal, “course_published” inherits django.dispatch.Signal and this slight modification seems benign in my case, aside from it not firing my handler that is.

Has anyone experienced similar behavior?

@lpm0073 Hi, I haven’t seen this particular case. But here’s a guess:

Could you try this instead?:
from xmodule.modulestore.django import SignalHandler, modulestore

I think that when Python lets you import a class in 2 ways, they’re not exactly the same. For instance you may have defined a signal handler for common.lib.xmodule.xmodule.modulestore.django.SignalHandler but the one which is firing is xmodule.modulestore.django import SignalHandler and they’re still unconnected.

1 Like

OMG!!! @clemente that was exactly the problem. THANK YOU!!! :smiley:

1 Like