Bird
0
0

Find the bug in this retry logic: ```python @app.task(bind=True, max_retries=2) def fetch_data(self): try: data = get_data() except Exception as exc: self.retry(exc=exc) ```

medium📝 Debug Q7 of 15
Django - Celery and Background Tasks
Find the bug in this retry logic: ```python @app.task(bind=True, max_retries=2) def fetch_data(self): try: data = get_data() except Exception as exc: self.retry(exc=exc) ```
Abind=True is unnecessary here.
Bmax_retries should be 3 or more.
CException variable should be named error.
DMissing raise before self.retry causes no retry.
Step-by-Step Solution
Solution:
  1. Step 1: Check retry call

    Retry must be raised with 'raise self.retry(...)' to trigger retry.
  2. Step 2: Identify missing raise

    The code calls self.retry but does not raise it, so retry won't happen.
  3. Final Answer:

    Missing raise before self.retry causes no retry. -> Option D
  4. Quick Check:

    Retry needs raise keyword [OK]
Quick Trick: Use 'raise' with self.retry to enable retry [OK]
Common Mistakes:
MISTAKES
  • Forgetting raise keyword
  • Changing max_retries unnecessarily
  • Misnaming exception variable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes