Bird
0
0

You wrote this signal handler but it runs for every model save, not just the intended one. What is the likely problem?

medium📝 Debug Q6 of 15
Django - Signals
You wrote this signal handler but it runs for every model save, not just the intended one. What is the likely problem?
from django.dispatch import receiver
from django.db.models.signals import post_save

@receiver(post_save)
def handler(sender, instance, **kwargs):
    print("Saved")
AMissing sender argument in the @receiver decorator
BHandler function missing required parameters
Cpost_save signal cannot be used with @receiver
Dprint statement syntax is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check the @receiver decorator usage

    The decorator lacks the sender argument, so it listens to post_save signals from all senders.
  2. Step 2: Understand why handler runs broadly

    Without specifying sender=YourModel, the handler triggers for every model that sends post_save.
  3. Final Answer:

    Missing sender argument in the @receiver decorator -> Option A
  4. Quick Check:

    Specify sender to ensure handler runs only for specific model [OK]
Quick Trick: Always specify sender in @receiver for model signals [OK]
Common Mistakes:
MISTAKES
  • Assuming handler runs without sender
  • Incorrect handler parameters
  • Thinking print syntax causes failure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes