Skip to content

How to Fix Python Django Signals Not Firing

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Python Django Signals Not Firing. We cover key concepts, practical examples, and best practices.

Django signals silently fail to execute when the receiver function is not properly connected, the module is not imported, or the signal is disconnected before firing.

The Wrong Way

# signals.py
from django.db.models.signals import post_save
from django.dispatch import receiver
from myapp.models import MyModel

@receiver(post_save, sender=MyModel)
def my_handler(sender, instance, **kwargs):
    print("Signal fired!")

Creating a MyModel instance produces no output.

The Right Way

# signals.py
from django.db.models.signals import post_save
from django.dispatch import receiver
from myapp.models import MyModel

@receiver(post_save, sender=MyModel)
def my_handler(sender, instance, **kwargs):
    print("Signal fired!")

# apps.py
from django.apps import AppConfig

class MyappConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'myapp'

    def ready(self):
        import myapp.signals

Now creating a MyModel prints "Signal fired!" in the console.

Prevention Tips

  • Always import signal modules in the ready() method of AppConfig.
  • Verify the sender model is imported and matches exactly.
  • Use dispatch_uid to prevent duplicate receivers.
  • Use m2m_changed for many-to-many field changes.
  • Debug signals by adding logging inside the receiver.

Common Mistakes with django signals

  1. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  2. Misunderstanding that String is [Char] with poor performance for large text operations
  3. Using foldl instead of foldl' causing stack overflow on large lists

These mistakes appear frequently in real-world PYTHON code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does my signal fire twice?

You may have registered the receiver twice. Use dispatch_uid as a unique identifier: @receiver(post_save, sender=MyModel, dispatch_uid="unique_id"). This prevents duplicate registrations.

What is the difference between pre_save and post_save?

pre_save fires before the model is saved to the database. post_save fires after. Use pre_save to modify the instance before persistence. Use post_save for actions that depend on the saved instance having an ID.

Can I disconnect a signal temporarily?

Yes, use Signal.disconnect() with the same arguments used to connect. Wrap the code in a try/finally block to reconnect if needed. Use Signal.connect() as a context manager in tests.

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro