Bird
0
0

Identify the error in this signal connection code:

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

def my_handler(sender, instance, **kwargs):
    print("Saved")

post_save.connect(my_handler)
AHandler function missing required parameters
BMissing sender argument in connect call
Cpost_save signal cannot be connected this way
DNo error; code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check connect call parameters

    The connect method usually requires a sender argument to specify which model triggers the signal.
  2. Step 2: Identify missing sender

    In this code, sender is not provided, so the handler connects to all senders, which may be unintended.
  3. Final Answer:

    Missing sender argument in connect call -> Option B
  4. Quick Check:

    Always specify sender unless global catch needed [OK]
Quick Trick: Always specify sender in connect unless global [OK]
Common Mistakes:
MISTAKES
  • Forgetting sender causes unintended connections
  • Assuming handler parameters are wrong
  • Thinking connect method is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes