Bird
0
0

Identify the error in this signal handler connection code:

medium📝 Debug Q14 of 15
Django - Signals
Identify the error in this signal handler connection code:
from django.db.models.signals import post_save
from django.dispatch import receiver

@receiver(post_save)
def handler(sender, instance, **kwargs):
    print('Saved!')
AMissing sender argument in @receiver decorator
BHandler function missing 'created' parameter
Cpost_save signal is not imported correctly
DHandler function should not have **kwargs
Step-by-Step Solution
Solution:
  1. Step 1: Check the @receiver decorator usage

    The @receiver decorator requires the signal and optionally the sender. Omitting sender means the handler listens to all senders, which is allowed but often unintended.
  2. Step 2: Identify the likely error

    Since the question asks for an error, the missing sender argument is the problem if the handler is meant for a specific model.
  3. Final Answer:

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

    Specify sender to target model signals [OK]
Quick Trick: Always specify sender to avoid catching all signals [OK]
Common Mistakes:
MISTAKES
  • Not specifying sender when needed
  • Assuming 'created' param is always required
  • Misunderstanding **kwargs usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes