Skip to content

Add task instance management commands to airflowctl CLI#67947

Open
Suraj-kumar00 wants to merge 19 commits into
apache:mainfrom
Suraj-kumar00:feat/task-instance-cli-support
Open

Add task instance management commands to airflowctl CLI#67947
Suraj-kumar00 wants to merge 19 commits into
apache:mainfrom
Suraj-kumar00:feat/task-instance-cli-support

Conversation

@Suraj-kumar00

@Suraj-kumar00 Suraj-kumar00 commented Jun 3, 2026

Copy link
Copy Markdown

Adds task instance management support to the airflowctl CLI, enabling users to get, list, clear, and update task instances directly from the terminal.

Closes: #61547
Related: #66173


Changes

airflow-ctl/src/airflowctl/api/operations.py

  • Added TasksOperations class (matching Airflow core CLI naming) with get, list, clear, and update methods
  • Restored PluginsOperations class that was lost during merge with main (Added plugins command to airflowctl #64935)

airflow-ctl/src/airflowctl/api/client.py

  • Added tasks property to Client for auto-generated CLI command wiring
  • Restored plugins property that was lost during merge with main

airflow-ctl/src/airflowctl/ctl/cli_config.py

  • Added "clear" to output_command_list for correct CLI output handling

airflow-ctl/src/airflowctl/ctl/help_texts.yaml

  • Added tasks: section with help text for all four subcommands

scripts/in_container/run_capture_airflowctl_help.py

  • Added "tasks" to the commands list for SVG/help image generation

airflow-ctl/tests/airflow_ctl/api/test_operations.py

  • Added TestTasksOperations with 7 unit tests covering get, list, clear, and update
  • Restored TestPluginsOperations tests lost during merge

airflow-ctl-tests/tests/airflowctl_tests/test_airflowctl_commands.py

  • Added end-to-end integration tests for all 4 tasks commands using positional arguments

CLI Commands

airflowctl tasks list   <dag_id> <dag_run_id>
airflowctl tasks get    <dag_id> <dag_run_id> <task_id>
airflowctl tasks clear  <dag_id> [--dry-run] [--only-failed] [--task-ids t1,t2]
airflowctl tasks update <dag_id> <dag_run_id> <task_id> [--new-state <state>] [--note <note>]
Screenshot 2026-06-04 at 1 21 52 AM Screenshot 2026-06-04 at 1 39 47 AM

@Suraj-kumar00 Suraj-kumar00 changed the title Feat/task instance cli support Add task instance management commands to airflowctl CLI Jun 3, 2026
@Suraj-kumar00 Suraj-kumar00 force-pushed the feat/task-instance-cli-support branch from bfb913a to 193ed6a Compare June 3, 2026 10:57
@Suraj-kumar00

Copy link
Copy Markdown
Author

Hello @potiuk,
Could you please review now and the CI Pipeline can be run?

Also could you help me get this that do i have to do the testing manually on local? This is taking so much time locally!!!

@bugraoz93 bugraoz93 added the full tests needed We need to run full set of tests for this PR to merge label Jun 3, 2026
@bugraoz93 bugraoz93 closed this Jun 3, 2026
@bugraoz93 bugraoz93 reopened this Jun 3, 2026

@bugraoz93 bugraoz93 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some foundational things needs changing, thanks for the PR!

Comment thread airflow-ctl-tests/tests/airflowctl_tests/test_airflowctl_commands.py Outdated
Comment thread airflow-ctl/src/airflowctl/api/operations.py Outdated
Comment thread airflow-ctl/src/airflowctl/ctl/cli_config.py Outdated
@Suraj-kumar00 Suraj-kumar00 force-pushed the feat/task-instance-cli-support branch from 0b76de6 to 400f426 Compare June 3, 2026 18:56
@Suraj-kumar00 Suraj-kumar00 requested a review from jscheffl as a code owner June 3, 2026 19:22
@Suraj-kumar00 Suraj-kumar00 force-pushed the feat/task-instance-cli-support branch from 4da1910 to a584bd1 Compare June 3, 2026 19:23
@Suraj-kumar00 Suraj-kumar00 requested a review from bugraoz93 June 3, 2026 20:19
@potiuk

potiuk commented Jun 9, 2026

Copy link
Copy Markdown
Member

@Suraj-kumar00 A few things need addressing before review — see our Pull Request quality criteria.

  • Pre-commit / static checks. See docs.

No rush.

Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you.

@Suraj-kumar00

Copy link
Copy Markdown
Author

Hi @potiuk, I'll make the changes tonight!

Comment on lines +740 to +744
if (
expanded_parameter in args_dict.keys()
and args_dict[expanded_parameter] is not None
):
val = args_dict[expanded_parameter]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, the None filtering is not strictly required for fields where null and “not provided” are equivalent. More importantly, this new path does not protect boolean fields, because the generated CLI currently defaults bool arguments to False. For ClearTaskInstancesBody, some API defaults are True or None (dry_run, only_failed, reset_dag_runs, run_on_latest_version), so airflowctl tasks clear <dag_id> may send explicit False values and override the API defaults.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right on both counts.

Fixed by changing the default from False to None for bool fields in _create_arg_for_non_primitive_type, so unset flags are now omitted from the request body and the API defaults apply. This also brings the path in sync with the primitive arg path, which already defaulted to None.

Added a regression test (test_command_factory_body_bool_field_defaults_to_none) using ClearTaskInstancesBody to lock it in.

Comment on lines +178 to +181
ansi_escape = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
out_str = ansi_escape.sub("", captured.out).replace("\n", "")
# Since rich wraps long lines, newlines are removed, so we assert the combined text.
assert out_str == f"Exported {len(exported_data)} pool(s) to {export_file}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could I ask why we need to change this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh, this was unintentional scope creep from local debugging of rich-rendered output. Reverted in the latest push.

Comment thread airflow-ctl/docs/images/output_main.svg
@Suraj-kumar00

Copy link
Copy Markdown
Author

Hello @henry3260,

I'm looking into this. Thanks for the review!

@bugraoz93 bugraoz93 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Henry's comments and could you please check CI what is failing on the integration tests and static checks

Comment thread airflow-ctl/docs/images/output_main.svg
…tanceOperations

- Remove bare re-raise try/except from get, clear, and update methods
- Fix ruff E302: add missing blank line before TaskInstanceOperations class
- Fix ruff F841: remove unused variable in pool command export test
- Run ruff format on operations.py, cli_config.py, test_operations.py
@Suraj-kumar00 Suraj-kumar00 force-pushed the feat/task-instance-cli-support branch from 81a9ef1 to f602199 Compare June 21, 2026 10:08
@Suraj-kumar00

Copy link
Copy Markdown
Author

Hi @henry3260 @potiuk,

I have made the changes as per the feedback, could you please review?

@Suraj-kumar00 Suraj-kumar00 requested a review from bugraoz93 June 21, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants