Bird
0
0

You wrote this Celery task in your Flask app:

medium📝 Debug Q14 of 15
Flask - Background Tasks
You wrote this Celery task in your Flask app:
@celery_app.task
def add(x, y):
return x + y
But when you call add.delay(2, 3), it raises an IndentationError. What is the problem?
Adelay() cannot be called on tasks
BThe function body is not indented properly
CYou forgot to import Celery
DThe decorator syntax is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check function indentation

    Python requires the function body to be indented under the def line.
  2. Step 2: Identify error cause

    Here, return x + y is not indented, causing IndentationError.
  3. Final Answer:

    The function body is not indented properly -> Option B
  4. Quick Check:

    Python needs indented function bodies [OK]
Quick Trick: Indent function body under def line [OK]
Common Mistakes:
MISTAKES
  • Ignoring Python indentation rules
  • Assuming delay() is invalid
  • Thinking decorator syntax is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes