Bird
0
0

What is wrong with this task definition?

medium📝 Debug Q7 of 15
Django - Celery and Background Tasks
What is wrong with this task definition?
from celery import shared_task

@shared_task
def process_data():
    data = fetch_data()
    return data

Assuming fetch_data() is not defined anywhere.
Afetch_data() is undefined, causing a NameError at runtime
BMissing @task decorator instead of @shared_task
CTask must have at least one argument
DReturn statements are not allowed in tasks
Step-by-Step Solution
Solution:
  1. Step 1: Check function calls inside task

    fetch_data() is called but not defined anywhere, causing an error.
  2. Step 2: Verify decorator and syntax

    @shared_task is correct; tasks can have no arguments and can return values.
  3. Final Answer:

    fetch_data() is undefined, causing a NameError at runtime -> Option A
  4. Quick Check:

    Undefined functions cause NameError [OK]
Quick Trick: Ensure all called functions are defined before use [OK]
Common Mistakes:
MISTAKES
  • Assuming decorator is wrong
  • Thinking tasks must have arguments
  • Believing return statements are disallowed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes