Add task instance management commands to airflowctl CLI#67947
Add task instance management commands to airflowctl CLI#67947Suraj-kumar00 wants to merge 4 commits into
Conversation
bfb913a to
193ed6a
Compare
|
Hello @potiuk, 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
left a comment
There was a problem hiding this comment.
There are some foundational things needs changing, thanks for the PR!
0b76de6 to
400f426
Compare
4da1910 to
a584bd1
Compare
|
@Suraj-kumar00 A few things need addressing before review — see our Pull Request quality criteria.
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. |
|
Hi @potiuk, I'll make the changes tonight! |
| if ( | ||
| expanded_parameter in args_dict.keys() | ||
| and args_dict[expanded_parameter] is not None | ||
| ): | ||
| val = args_dict[expanded_parameter] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Hello @henry3260, I'm looking into this. Thanks for the review! |
bugraoz93
left a comment
There was a problem hiding this comment.
I agree with Henry's comments and could you please check CI what is failing on the integration tests and static checks
81a9ef1 to
f602199
Compare
|
Hi @henry3260 @potiuk, I have made the changes as per the feedback, could you please review? |
|
Hi @henry3260 @potiuk, Let me know the feedback once you get the time to look into this. Thanks! |
67381fe to
93cf5cd
Compare
aaron-y-chen
left a comment
There was a problem hiding this comment.
Hi, thanks for the PR :)
There was a problem hiding this comment.
Pull request overview
Adds a new airflowctl tasks command group backed by REST API v2 Task Instance endpoints, plus related CLI generation fixes and documentation artifacts for the new commands.
Changes:
- Introduces
TasksOperationsand wires it into theClientto exposetasks get/list/clear/update. - Updates CLI command generation to avoid forcing unset boolean body fields to
False, and adds small output/pagination handling tweaks. - Extends help text, help-capture scripting, and adds unit + end-to-end tests for the new tasks commands.
Reviewed changes
Copilot reviewed 9 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/in_container/run_capture_airflowctl_help.py | Adds tasks to the list of commands captured for help-image generation. |
| airflow-ctl/tests/airflow_ctl/ctl/test_cli_config.py | Updates/extends CLI factory tests to ensure boolean body fields default to None and stay unset unless provided. |
| airflow-ctl/tests/airflow_ctl/api/test_operations.py | Adds unit tests for TasksOperations plus restores/adjusts plugin tests and adds pool PATCH behavior tests. |
| airflow-ctl/src/airflowctl/ctl/help_texts.yaml | Adds help text entries for the new tasks subcommands. |
| airflow-ctl/src/airflowctl/ctl/cli_config.py | Adjusts CLI arg generation/output rules and improves body-param expansion (bool defaults, list CSV parsing). |
| airflow-ctl/src/airflowctl/api/operations.py | Adds TasksOperations and updates pool PATCH behavior to always send include_deferred. |
| airflow-ctl/src/airflowctl/api/client.py | Adds the tasks operations property (and restores plugins). |
| airflow-ctl/docs/images/output_tasks.svg | New generated help output image for airflowctl tasks. |
| airflow-ctl/docs/images/output_main.svg | Regenerated main help output image to include the new tasks group. |
| airflow-ctl/docs/images/command_hashes.txt | Updates command hashes to include tasks and reflect regenerated outputs. |
| airflow-ctl-tests/tests/airflowctl_tests/test_airflowctl_commands.py | Adds end-to-end command invocations covering all tasks subcommands. |
|
Hello @nailo2c, thanks for the review I'll be pushing the changes soon, and will keep you posted on this. |
|
Hi @potiuk, I'll be able to push the changes tomorrow. |
|
Hi @nailo2c @potiuk, I have made the changes as per the feedback, could you please review? |
|
Could you address the requested changes from henry3260 and bugraoz93? |
| arg_action=argparse.BooleanOptionalAction if annotation is bool else None, # type: ignore | ||
| arg_help=f"{field} for {parameter_key} operation", | ||
| arg_default=False if annotation is bool else None, | ||
| arg_default=None, |
There was a problem hiding this comment.
This was addressing henry3260's comment: the generated CLI hard-coded False for every bool body flag, so tasks clear sent dry_run=False and only_failed=False, overriding the API defaults of True and turning a dry run into a real clear. Reworked per your other comments: no more None. Each generated bool flag now defaults to its datamodel field's own default (the generated client models carry the API defaults from the OpenAPI spec), falling back to False. Every flag is a concrete True or False, and existing commands are unaffected since their models' bool defaults are already False.
There was a problem hiding this comment.
Ah right, taking the default from the API makes some sense.
For what it's worth then, rather than, rather using None as not set, I'd rather we used an explicit NotSet / ARG_NOT_SET sentinel value. I don't know if we do that elsewhere in the airflowctl, but we do have that elsewhere in airflow codebase.
64c4bd9 to
bfbbdcf
Compare
All addressed in the latest push: henry3260's bool-defaults issue is fixed by sourcing flag defaults from the datamodels (see thread above), his pool test question was resolved by reverting that file, and the help images/hashes are regenerated. bugraoz93's requests (positional required params, tasks naming to match core CLI) are in. The branch is also squashed onto latest main for a clean diff. One open question remains on the operations class naming, see ashb's thread. |
| def _get_bool_flag_default(field_info: Any) -> bool: | ||
| """Return the CLI default for a generated bool flag: the datamodel field's default (the API default), or False.""" | ||
| return field_info.default if isinstance(field_info.default, bool) else False |
| # datamodel default is None (fallback semantics), so the flag falls back to False | ||
| "--run-on-latest-version": False, | ||
| } |
|
cc @ashb @bugraoz93 @potiuk @Suraj-kumar00 Following up on the naming discussion in the review thread ( I have started that discussion: https://lists.apache.org/thread/32oqb3j7f22mlj12t2q95f5n4fqzhlcp It frames the general question — should the user-facing command surface align with REST API resources, or keep parity with the Since the class name here directly determines the user-facing command group, it may be worth reaching consensus there first before merging this PR — that would avoid shipping the commands under a name that might immediately need a breaking rename. |
Awesome, thanks for creating the discussion! |
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.pyTasksOperationsclass (matching Airflow core CLI naming) withget,list,clear, andupdatemethodsPluginsOperationsclass that was lost during merge with main (Added plugins command to airflowctl #64935)airflow-ctl/src/airflowctl/api/client.pytasksproperty toClientfor auto-generated CLI command wiringpluginsproperty that was lost during merge with mainairflow-ctl/src/airflowctl/ctl/cli_config.py"clear"tooutput_command_listfor correct CLI output handlingairflow-ctl/src/airflowctl/ctl/help_texts.yamltasks:section with help text for all four subcommandsscripts/in_container/run_capture_airflowctl_help.py"tasks"to the commands list for SVG/help image generationairflow-ctl/tests/airflow_ctl/api/test_operations.pyTestTasksOperationswith 7 unit tests covering get, list, clear, and updateTestPluginsOperationstests lost during mergeairflow-ctl-tests/tests/airflowctl_tests/test_airflowctl_commands.pytaskscommands using positional argumentsCLI Commands
Important
🛠️ Maintainer triage note for @Suraj-kumar00 · by
@potiuk· 2026-07-08 15:38 UTCHelpful heads-up from the maintainers — please address before this PR can be reviewed:
Helm tests / Unit tests Helm: security (K8S 1.30.13)). See the contributor guide.Full criteria: Pull Request quality criteria.
The ball is in your court — you've been assigned to this PR. Fix the above, then mark it Ready for review.
Automated triage — may be imperfect; a maintainer takes the next look.