Skip to content

Instantly share code, notes, and snippets.

@manutheblacker
Created December 10, 2023 14:34
Show Gist options
  • Save manutheblacker/be4008251bc584aee5c057bf461126cb to your computer and use it in GitHub Desktop.
Save manutheblacker/be4008251bc584aee5c057bf461126cb to your computer and use it in GitHub Desktop.
How to do when Django signals isn't sending in production ?

Hello, I've encountered an issue with a Django project that I was running under CyberPanel 3.

Normally, under certain conditions, when new data is saved to the database, a new identifier is created for the field. While testing locally, it worked as expected, but in production, it failed to send.

After some research, I realized that signals must be loaded, either by adding them to the ready() method in the apps.py file, like this, and ensuring that the app is loaded into settings.py, as in my case: 'users.apps.UsersConfig'

class UsersConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'users'

    def ready(self):
        import users.signals

Alternatively, you can add a line to the __init__.py file as follows:

default_app_config = 'users.apps.UsersConfig'

If the issue persists after loading these, make sure that the receiver callback arguments contain the weak attribute, which means the signals won't be garbage collected, like this:

@receiver(post_save, sender=Users, dispatch_uid="update_users", weak=False)

Also, ensure that the callback the receiver will use doesn't have the same name.

Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment