noahwons opened a new pull request, #66386: URL: https://github.com/apache/airflow/pull/66386
# Title airflowctl: add `tasks clear` command (closes #66176) # Body Closes #66176. Builds on top of #[66174](https://github.com/apache/airflow/pull/66384) (PR for #66174) and #[66175](https://github.com/apache/airflow/pull/66385) (PR for #66175). ## What this PR does Adds the `airflowctl tasks clear` subcommand. Clears task instances in a DAG run with the same filtering options as the legacy `airflow tasks clear` command — only-failed, only-running, upstream, downstream, include-past, include-future, reset-dag-runs, and a `--dry-run` mode that previews what would be cleared without actually clearing. ## Implementation summary - New `clear_tis` method on the `TasksOperations` class added in #______, wrapping `POST /dags/{dag_id}/clearTaskInstances`. The request body is constructed from the existing `ClearTaskInstancesBody` Pydantic model in the auto-generated datamodels. - New `clear` command function in `airflow-ctl/src/airflowctl/ctl/commands/tasks_command.py`. In `--dry-run` mode, prints the list of task instances that would be cleared. Otherwise prints the count and exits. - New CLI argument definitions in `cli_config.py`: `ARG_DRY_RUN`, `ARG_ONLY_FAILED`, `ARG_ONLY_RUNNING`, `ARG_TASK_UPSTREAM`, `ARG_TASK_DOWNSTREAM`, `ARG_INCLUDE_PAST`, `ARG_INCLUDE_FUTURE`, `ARG_RESET_DAG_RUNS`, `ARG_TASK_IDS`, `ARG_TASK_START_DATE`, `ARG_TASK_END_DATE`. - New `ActionCommand` registered in `TASKS_COMMANDS` with `name="clear"`. - Test for the `--dry-run` path in `test_tasks_command.py`. - Newsfragment in `airflow-ctl/newsfragments/`. ## Testing - `pytest airflow-ctl/tests/airflow_ctl/ctl/commands/test_tasks_command.py::TestTasksCommands::test_tasks_clear_dry_run -v` — passes. - Manually verified `--dry-run` against a local Breeze-started Airflow: ``` $ airflowctl tasks clear my_dag manual__2025-01-01T00:00:00+00:00 --dry-run --only-failed Would clear 1 task instance(s). [{"task_id": "transform", "run_id": "manual__2025-01-01T00:00:00+00:00", "state": "failed"}] ``` - Manually verified actual clearing (without `--dry-run`) and confirmed the affected task instance state was reset in the UI. ## AI-assistance disclosure Per the project's contribution policy: this PR was developed with AI assistance for code drafting and analysis. All code has been reviewed, manually tested by the contributor, and the contributor can explain and defend the changes during review. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
