Skip to content

Add state command to airflowctl tasks - #72163

Closed
itzzdev09 wants to merge 4 commits into
apache:mainfrom
itzzdev09:airflowctl-tasks-state
Closed

itzzdev09 wants to merge 4 commits into
apache:mainfrom
itzzdev09:airflowctl-tasks-state

Conversation

@itzzdev09

@itzzdev09 itzzdev09 commented Aug 27, 2026 •

Copy link
Copy Markdown

Adds airflowctl tasks state, the missing counterpart to the deprecated airflow tasks state, which is already annotated @deprecated_for_airflowctl("airflowctl tasks state") in airflow-core/src/airflow/cli/commands/task_command.py but had nothing to point at.

The command selects a Dag run with either run_id or --logical-date and prints the state of the task instance. It goes through the existing task_instances.get endpoint, so no change to operations.py was needed.

To stay consistent with the sibling commands, it reuses the argument handling, validation and error wording already used by tasks failed-deps:

  • exactly one of run_id / --logical-date is required
  • --logical-date must be parseable and timezone-aware
  • --map-index is reported in the 404 message, so a missing mapped instance is distinguishable from a missing task
  • non-404 API errors propagate rather than being swallowed

It prints None for a task instance with no state, matching the output of the deprecated command so scripts migrating across keep working.

$ airflowctl tasks state example_dag run_this manual__2025-01-01T00:00:00+00:00
success

closes: #66174

Tests

16 new tests in TestState covering state values, unset state, map index, logical-date lookup, both argument-validation failures, bad logical dates, 404 handling with and without a map index, missing Dag run, and non-404 propagation.

46 passed for the full test_task_command.py file — no existing test was modified. ruff check, ruff format --check and mypy are clean on the changed files.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Sonnet 5)

Generated-by: Claude Code (Sonnet 5) following the guidelines

Adds `airflowctl tasks state`, the replacement for the deprecated
`airflow tasks state` command, which is already marked
`@deprecated_for_airflowctl("airflowctl tasks state")` but had no
airflowctl counterpart.

The command selects a Dag run with either `run_id` or `--logical-date`
and prints the state of the task instance, reusing the existing
`task_instances.get` endpoint. It follows the argument handling, error
messages and map-index reporting already used by `tasks failed-deps`,
and prints "None" for an unset state so scripts migrating off the
deprecated command keep working.
@boring-cyborg

boring-cyborg Bot commented Aug 27, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@SameerMesiah97 SameerMesiah97 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.

Left some comments. Also, I believe this needs a newsfragment as it is in airflow core.

CI needs to be triggered too.

Comment thread airflow-ctl/src/airflowctl/ctl/commands/task_command.py Outdated
Comment thread airflow-ctl/src/airflowctl/ctl/cli_config.py Outdated
@itzzdev09

Copy link
Copy Markdown
Author

Thanks for the review @SameerMesiah97 — pushed 2e1d575 addressing both comments, replies inline.

  • Run selection is now explicit (named booleans + if/else). I kept the check covering the "neither given" case too, since dropping it would turn that input into an AttributeError instead of a clean exit — details in the thread.
  • Help text now states the selection rule. On the ordering question: DagRun has UniqueConstraint("dag_id", "logical_date"), so an exact logical-date match can only ever return one run — order_by="-id" isn't disambiguating anything. I left the shared _find_run_id_by_logical_date helper alone because tasks failed-deps and tasks states-for-dag-run use it too; happy to clean it up as a follow-up.
  • Newsfragment added as airflow-core/newsfragments/72163.feature.rst. Worth flagging: there's no airflow-ctl/newsfragments directory, and contributing-docs/18_contribution_workflow.rst only lists airflow-core and chart as destinations. This change is in airflow-ctl rather than core, so let me know if it belongs elsewhere or should be dropped.

On CI — the workflows are still awaiting approval, which I can't trigger myself as a first-time contributor. Could you kick that off when you get a chance?

@itzzdev09

Copy link
Copy Markdown
Author

Pushed 0903e25 — this fixes the static-checks failure on the earlier run.

The cause was the generate-airflowctl-help-images prek hook: it regenerates the CLI help SVGs from cli_config.py, so adding a tasks subcommand left the checked-in output_tasks.svg (and its entry in command_hashes.txt) stale, and the hook failed with "files were modified by this hook".

output_tasks.svg and the tasks hash are now regenerated. As a check that I reproduced the generation faithfully rather than just producing something plausible, I regenerated the other 16 commands too — all of their hashes and images come out byte-identical to what's committed, so the only changes in the diff are the tasks line and its image:

-tasks:ea587dc805cadbce81cd640d357f2661
+tasks:eb70701dfe1b9baeda39d5eea07fde5f

The new image lists the command in its alphabetical slot:

failed-deps          Returns the unmet dependencies for a task instance
state                Get the state of a task instance
states-for-dag-run   Get the status of all task instances in a Dag run

Workflows are showing action_required again on the new commit — could you re-approve when you have a moment?

@SameerMesiah97

Copy link
Copy Markdown
Contributor

Pushed 0903e25 — this fixes the static-checks failure on the earlier run.

The cause was the generate-airflowctl-help-images prek hook: it regenerates the CLI help SVGs from cli_config.py, so adding a tasks subcommand left the checked-in output_tasks.svg (and its entry in command_hashes.txt) stale, and the hook failed with "files were modified by this hook".

output_tasks.svg and the tasks hash are now regenerated. As a check that I reproduced the generation faithfully rather than just producing something plausible, I regenerated the other 16 commands too — all of their hashes and images come out byte-identical to what's committed, so the only changes in the diff are the tasks line and its image:

-tasks:ea587dc805cadbce81cd640d357f2661
+tasks:eb70701dfe1b9baeda39d5eea07fde5f

The new image lists the command in its alphabetical slot:

failed-deps          Returns the unmet dependencies for a task instance
state                Get the state of a task instance
states-for-dag-run   Get the status of all task instances in a Dag run

Workflows are showing action_required again on the new commit — could you re-approve when you have a moment?

I can’t trigger CI. I don’t have the privileges.

@potiuk could you help with that?

itzzdev09 and others added 2 commits August 28, 2026 22:08
- Make the run_id / --logical-date validation explicit with named booleans and
  an if/else instead of the compact 'or' shortcut.
- Note in the command description that --logical-date matches the Dag run with
  exactly that logical date.
- Add the newsfragment for the new command.

Co-authored-by: SameerMesiah97 <75502260+SameerMesiah97@users.noreply.github.com>
The generate-airflowctl-help-images prek hook regenerates the CLI help SVGs
from cli_config.py, so adding the 'tasks state' command left the checked-in
output_tasks.svg and its hash stale and failed static checks.
@itzzdev09
itzzdev09 force-pushed the airflowctl-tasks-state branch from 0903e25 to 9b6b10c Compare August 28, 2026 16:40
@itzzdev09

Copy link
Copy Markdown
Author

Heads up on a force-push just now (0903e25 → 9b6b10c): the file contents are byte-identical to before — I verified the tree hashes match — the only change is that I added a Co-authored-by: trailer crediting @SameerMesiah97 on the review-fix commit, since the explicit run-selection structure came from your suggestion.

Both commits are otherwise untouched, and the PR is still MERGEABLE.

Comment thread airflow-core/newsfragments/72163.feature.rst Outdated
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@kaxil

kaxil commented Oct 1, 2026

Copy link
Copy Markdown
Member

Closing this. #71206 was opened three weeks earlier for #66174 and has been approved.

@kaxil kaxil closed this Oct 1, 2026
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.

[AIP-94] airflowctl tasks: add state command

4 participants