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 pre_save

def handler(sender, instance, **kwargs):
    print("Saving instance")

pre_save.connect(handler)
AHandler function missing required parameters
BMissing sender argument in connect call
CSignal should be post_save, not pre_save
Dconnect method called on handler instead of signal
Step-by-Step Solution
Solution:
  1. Step 1: Check connect method usage

    When connecting a signal, sender argument is often required to specify which model triggers it.
  2. Step 2: Identify missing sender

    The code calls pre_save.connect(handler) without sender, which may cause the handler to receive signals from all models unintentionally.
  3. Final Answer:

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

    Connect missing sender = error [OK]
Quick Trick: Always specify sender when connecting signals [OK]
Common Mistakes:
MISTAKES
  • Omitting sender causes broad signal reception
  • Confusing pre_save with post_save
  • Calling connect on handler instead of signal

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes