Django - Signal receiver not being called

Viewed 450

I am working on a project utilizing Django All Auth.

Inside the package, there is an account.signals file that contains a signal.

email_confirmed = Signal(providing_args=["request", "email_address"]).

It is used inside of a model for EmailConfirmationHMAC.

def confirm(self, request):
        if not self.email_address.verified:
            email_address = self.email_address
            get_adapter(request).confirm_email(request, email_address)
            signals.email_confirmed.send(sender=self.__class__,
                                         request=request,
                                         email_address=email_address)
            return email_address

Adding a stack trace in here, I can see it is getting to this part.

Inside my project, I have a python file receivers.py

from allauth.account.signals import email_confirmed
from django.dispatch import receiver


@receiver(email_confirmed)
def custom_logic(sender, **kwargs):
    a = 0
    import ipdb;
    ipdb.set_trace()
    if a:
        pass

However, whenever I confirm an email verification my custom logic debugger is not being hit, the email is being confirmed and the page is being re-routed.

How do I ensure that my custom_logic function can be ran, after the signal is sent?

 signals.email_confirmed.send(sender=self.__class__,
                                         request=request,
                                         email_address=email_address)

Thanks!

1 Answers

So the issue was with how I had my signals imported.

Under apps.py I added the following:

from django.apps import AppConfig


class AuthUsersConfig(AppConfig):
    name = 'auth_users'

    def ready(self):
        import auth_users.signals

And then inside my __init__.py I added:

default_app_config = 'auth_users.apps.AuthUsersConfig'

After that, when I hit the endpoint, the custom logic I was using started working.

Related