How to Use airflow test Command for Task Debugging
airflow test command to run a single task instance of a DAG for a specific execution date without changing the DAG's state. The syntax is airflow test DAG_ID TASK_ID EXECUTION_DATE, which helps debug tasks quickly.Syntax
The airflow test command runs a single task instance for a given DAG and execution date without updating the task state in the Airflow metadata database.
- DAG_ID: The ID of the DAG containing the task.
- TASK_ID: The ID of the task to run.
- EXECUTION_DATE: The logical date for the task run in
YYYY-MM-DDorYYYY-MM-DDTHH:MM:SSformat.
airflow test DAG_ID TASK_ID EXECUTION_DATE
Example
This example runs the task print_date from the DAG example_bash_operator for the execution date 2023-06-01. It helps verify the task runs correctly without affecting the DAG's state.
airflow test example_bash_operator print_date 2023-06-01
Common Pitfalls
1. Misunderstanding state changes: airflow test does not update task or DAG run states, so it won't mark tasks as success or failure in the UI.
2. Wrong execution date format: Use ISO format YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS. Incorrect formats cause errors.
3. Running tasks with dependencies: airflow test runs only the specified task without upstream or downstream tasks, so it may fail if dependencies are required.
Wrong usage example (missing execution date): airflow test example_bash_operator print_date Correct usage: airflow test example_bash_operator print_date 2023-06-01
Quick Reference
Tips for using airflow test:
- Use it to debug individual tasks quickly without affecting DAG state.
- Always provide a valid execution date in ISO format.
- Remember it does not run task dependencies.
- Check task logs for detailed output after running.
Key Takeaways
airflow test DAG_ID TASK_ID EXECUTION_DATE to run a single task instance without changing DAG state.airflow test does not run upstream or downstream tasks, only the specified task.