Bird
0
0

Examine this Celery task code snippet. What is the issue with the retry call?

medium📝 Debug Q6 of 15
Django - Celery and Background Tasks
Examine this Celery task code snippet. What is the issue with the retry call?
@app.task(bind=True)
def send_report(self):
    try:
        generate_report()
    except Exception as error:
        self.retry(error, countdown=60)
AThe exception should be passed as a keyword argument 'exc', not as a positional argument
BThe countdown parameter is invalid and should be removed
CThe task is missing max_retries parameter, so retry won't work
DThe retry method cannot be called inside an except block
Step-by-Step Solution
Solution:
  1. Step 1: Review retry method signature

    Celery's retry method expects the exception to be passed as a keyword argument 'exc=error'.
  2. Step 2: Identify the error

    Passing the exception as a positional argument causes a TypeError.
  3. Step 3: Validate other options

    Countdown is valid, max_retries is optional, and retry can be called inside except blocks.
  4. Final Answer:

    The exception should be passed as a keyword argument 'exc', not as a positional argument -> Option A
  5. Quick Check:

    Use exc=exception in retry() call [OK]
Quick Trick: Use exc=exception in retry() call [OK]
Common Mistakes:
MISTAKES
  • Passing exception as positional argument
  • Omitting exc keyword causes errors
  • Misunderstanding retry call placement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes