Skip to content

Not able to clear a task instance using CLI command #48430

Description

@atuls4441

Apache Airflow version

main (development)

If "Other Airflow 2 version" selected, which one?

No response

What happened?

$ airflow tasks clear test_api_dag
[2025-03-27T06:05:38.953+0000] {dagbag.py:575} INFO - Filling up the DagBag from /root/airflow/dags
[2025-03-27T06:05:41.156+0000] {cli.py:282} WARNING - Dag '\x1b[1mtest_api_dag\x1b[22m' not found in path /root/airflow/dags; trying path /root/airflow/dags
[2025-03-27T06:05:41.157+0000] {dagbag.py:575} INFO - Filling up the DagBag from /root/airflow/dags
Traceback (most recent call last):
  File "/usr/local/bin/airflow", line 10, in <module>
    sys.exit(main())
  File "/opt/airflow/airflow-core/src/airflow/__main__.py", line 58, in main
    args.func(args)
  File "/opt/airflow/airflow-core/src/airflow/cli/cli_config.py", line 49, in command
    return func(*args, **kwargs)
  File "/opt/airflow/airflow-core/src/airflow/utils/cli.py", line 111, in wrapper
    return f(*args, **kwargs)
  File "/opt/airflow/airflow-core/src/airflow/utils/providers_configuration_loader.py", line 55, in wrapped_function
    return func(*args, **kwargs)
  File "/opt/airflow/airflow-core/src/airflow/cli/commands/task_command.py", line 464, in task_clear
    DAG.clear_dags(
  File "/opt/airflow/airflow-core/src/airflow/models/dag.py", line 1544, in clear_dags
    tis = dag.clear(
AttributeError: 'DAG' object has no attribute 'clear'

What you think should happen instead?

No response

How to reproduce

Have a dagrun created for a dag and then run CLI command to clear task instances

from datetime import datetime

from airflow.providers.standard.operators.bash import BashOperator
from airflow.sdk import DAG

dag = DAG(
    'test_api_dag',
    start_date=datetime(2025, 3, 1, 3, 28, 0),
    schedule='@daily',
    is_paused_upon_creation=False
)

hello_task = BashOperator(
    task_id='test_task',
    bash_command='echo "Hello World from Airflow!"',
    do_xcom_push = True,
    dag=dag,
)

hello_task

airflow tasks clear <dag_id>

Operating System

Linux

Versions of Apache Airflow Providers

No response

Deployment

Other

Deployment details

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    needs-triage
    on Mar 27, 2025
  2. added
    priority:high
    and removed
    needs-triage
    on Mar 27, 2025
  3. bugraoz93 commented on Mar 27, 2025

    @bugraoz93
    Contributor

    I will take a look at this @vatsrahul1001 if it is okay for you. Thanks for creating!

  4. self-assigned this
    on Mar 27, 2025
  5. added a commit that references this issue on Mar 28, 2025
    fa8834c
  6. added a commit that references this issue on Mar 28, 2025
    c96b5af
  7. added a commit that references this issue on Apr 2, 2025
    11a6dba
  8. added this to the Airflow 3.0.0 milestone on Apr 15, 2025
  9. vatsrahul1001 commented on Apr 23, 2025

    @vatsrahul1001
    Contributor

    @atul-astronomer was able repro this with RC4

  10. added
    priority:medium
    and removed
    priority:high
    on Apr 23, 2025
  11. added
    priority:high
    and removed
    priority:medium
    on Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

affected_version:3.0area:CLIarea:corekind:bugpriority:high

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions