C. Missing self parameter in task function definition
D. Incorrect exception handling syntax
Solution
Step 1: Check function signature for bound task
With bind=True, the task function must accept self as first parameter.
Step 2: Verify usage of self.retry
self.retry is called, but self is undefined because function lacks self parameter.
Final Answer:
Missing self parameter in task function definition -> Option C
Quick Check:
bind=True requires self parameter [OK]
Hint: bind=True means add self parameter to task function [OK]
Common Mistakes:
Forgetting self parameter with bind=True
Calling retry outside except block
Assuming max_retries is mandatory for retry
5. You want a Django Celery task to retry only on network errors but fail immediately on other exceptions. Which approach correctly implements this behavior?
hard
A. Set max_retries=0 and catch all exceptions to call self.retry
B. Use try-except to catch network errors and call self.retry; re-raise other exceptions
C. Call self.retry unconditionally in except block for all exceptions
D. Use a decorator to retry on all exceptions automatically
Solution
Step 1: Differentiate exception types in except block
Catch only network-related exceptions to retry, others should raise immediately.
Step 2: Use self.retry only for network errors
Call self.retry inside except for network errors; re-raise other exceptions to fail fast.
Final Answer:
Use try-except to catch network errors and call self.retry; re-raise other exceptions -> Option B
Quick Check:
Retry selectively by exception type using try-except [OK]
Hint: Retry only inside except for specific exceptions [OK]