Bird
0
0

Identify the error in this Celery task definition in a Flask app:

medium📝 Debug Q6 of 15
Flask - Background Tasks
Identify the error in this Celery task definition in a Flask app:
from celery import Celery
celery = Celery(__name__, broker='redis://localhost:6379/0')
@celery.task
def send_email():
print('Email sent')
AIncorrect broker URL format
BMissing indentation inside the task function
CTask function must return a value
DCelery instance not linked to Flask app
Step-by-Step Solution
Solution:
  1. Step 1: Check Python syntax in task function

    The print statement inside send_email() is not indented, causing a syntax error.
  2. Step 2: Verify other parts

    Broker URL format is correct, returning value is optional, and linking to Flask app is not mandatory here.
  3. Final Answer:

    Missing indentation inside the task function -> Option B
  4. Quick Check:

    Python indentation error inside task [OK]
Quick Trick: Indent task function body properly in Python [OK]
Common Mistakes:
MISTAKES
  • Ignoring Python indentation rules
  • Assuming task must return value
  • Confusing broker URL format

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes