How to Clear Task Instance in Airflow: Simple Commands and Examples
To clear a task instance in Airflow, use the
airflow tasks clear command with the DAG ID and task ID. This resets the task state so it can be rerun. You can also clear tasks from the Airflow web UI by selecting the task and clicking 'Clear'.Syntax
The basic syntax to clear a task instance using the Airflow CLI is:
airflow tasks clear <dag_id> <task_id> --start-date <start_date> --end-date <end_date>--start-dateand--end-datedefine the date range of the task instances to clear.- Use
--yesto skip confirmation prompt.
bash
airflow tasks clear <dag_id> <task_id> --start-date YYYY-MM-DD --end-date YYYY-MM-DD [--yes]
Example
This example clears the task instance for task process_data in DAG example_dag for the date 2024-06-01. It resets the task state so Airflow can rerun it.
bash
airflow tasks clear example_dag process_data --start-date 2024-06-01 --end-date 2024-06-01 --yes
Output
INFO - Clearing task instances from example_dag.process_data for 2024-06-01 to 2024-06-01
INFO - 1 task instance cleared.
Common Pitfalls
- Not specifying the correct
start-dateandend-datecan clear unintended task instances. - Forgetting
--yescauses a confirmation prompt that blocks automation scripts. - Clearing tasks without understanding dependencies may cause unexpected DAG behavior.
- Trying to clear tasks from a paused DAG will not rerun them until the DAG is unpaused.
bash
## Wrong: Missing date range airflow tasks clear example_dag process_data ## Right: Specify date range and confirm airflow tasks clear example_dag process_data --start-date 2024-06-01 --end-date 2024-06-01 --yes
Quick Reference
Use this cheat sheet to clear task instances quickly:
| Command | Description |
|---|---|
| airflow tasks clear | Clear task instances in date range without prompt |
| airflow dags unpause | Unpause DAG to allow rerun after clearing |
| Use Airflow UI > Graph View > Select task > Clear | Clear task instance via web interface |
Key Takeaways
Use the CLI command
airflow tasks clear with correct DAG, task, and date range to reset task instances.Always specify
--start-date and --end-date to avoid clearing wrong tasks.Add
--yes to skip confirmation for automation.Clearing tasks only resets state; ensure the DAG is unpaused to rerun tasks.
You can also clear tasks easily from the Airflow web UI.