Skip to content

Add tasks state command to airflowctl#66202

Open
hyungryuk wants to merge 2 commits intoapache:mainfrom
hyungryuk:API-94-add-state-command
Open

Add tasks state command to airflowctl#66202
hyungryuk wants to merge 2 commits intoapache:mainfrom
hyungryuk:API-94-add-state-command

Conversation

@hyungryuk
Copy link
Copy Markdown

  • Add TaskInstancesOperations to operations.py and wire task_instances property in client.py
  • Add task_state command to new task_command.py that calls GET /api/v2/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id} and outputs {"state": ...} via AirflowConsole
  • Wire airflowctl tasks state --dag-id --dag-run-id --task-id in cli_config.py
  • Add taskinstances get help text to help_texts.yaml and integration test to test_airflowctl_commands.py

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@boring-cyborg
Copy link
Copy Markdown

boring-cyborg Bot commented May 1, 2026

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

Copy link
Copy Markdown
Contributor

@henry3260 henry3260 left a comment

Choose a reason for hiding this comment

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

Thanks for your PR!
Could we add corresponding tests to cover this feature?

Comment on lines +27 to +31
ti = api_client.task_instances.get(
dag_id=args.dag_id,
dag_run_id=args.dag_run_id,
task_id=args.task_id,
)
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 think we should add a try-except block to catch errors.

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.

@henry3260 Thanks for reviewing my PR!
I believe this is already handled by the safe_call_command function. It captures server error messages and prints them out as shown in the attached image.

Image

@hyungryuk hyungryuk force-pushed the API-94-add-state-command branch 2 times, most recently from fc66067 to 2157b46 Compare May 2, 2026 03:42
@hyungryuk
Copy link
Copy Markdown
Author

Thanks for your PR! Could we add corresponding tests to cover this feature?

No problem! I've just added the tests to cover this feature. Let me know if they look good to you.

@hyungryuk hyungryuk requested a review from henry3260 May 2, 2026 03:45
@hyungryuk hyungryuk force-pushed the API-94-add-state-command branch from 2157b46 to 15cf0f0 Compare May 2, 2026 07:16
Copy link
Copy Markdown
Contributor

@parkhojeong parkhojeong left a comment

Choose a reason for hiding this comment

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

i checked term usage :)

Comment thread airflow-ctl-tests/tests/airflowctl_tests/test_airflowctl_commands.py Outdated
@hyungryuk
Copy link
Copy Markdown
Author

i checked term usage :)

@parkhojeong Appreciate that! Thanks for checking.

@hyungryuk hyungryuk force-pushed the API-94-add-state-command branch from 4b2f9a4 to be7243b Compare May 2, 2026 15:04
@hyungryuk hyungryuk requested a review from ephraimbuddy as a code owner May 2, 2026 15:04
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.

This appears to be an unrelated change. You might need a rebase (:

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.

Thanks. Just rebased it and cleaned up the commits.

@hyungryuk hyungryuk force-pushed the API-94-add-state-command branch from be7243b to 30689b2 Compare May 3, 2026 01:56
@hyungryuk hyungryuk force-pushed the API-94-add-state-command branch from 30689b2 to 86529ac Compare May 3, 2026 06:14
hyungryuk added 2 commits May 3, 2026 18:24
  Introduce `airflowctl tasks state` to retrieve the state of a task
  instance by calling GET /api/v2/dags/{dag_id}/dagRuns/{run_id}/
  taskInstances/{task_id}. Also add TaskInstancesOperations, help text,
  and an integration test for the auto-generated taskinstances get command.

# Conflicts:
#	airflow-ctl-tests/tests/airflowctl_tests/test_airflowctl_commands.py
@hyungryuk hyungryuk force-pushed the API-94-add-state-command branch from 86529ac to f1e9062 Compare May 3, 2026 09:24
Copy link
Copy Markdown
Contributor

@parkhojeong parkhojeong left a comment

Choose a reason for hiding this comment

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

This looks like a useful feature!

class TaskInstancesOperations(BaseOperations):
"""Task instance operations."""

def get(self, dag_id: str, dag_run_id: str, task_id: str) -> TaskInstanceResponse | ServerResponseError:
Copy link
Copy Markdown
Contributor

@parkhojeong parkhojeong May 4, 2026

Choose a reason for hiding this comment

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

I think mapped task instances are currently missing from this implementation.

A task instance is not always identified only by (dag_id, dag_run_id, task_id). For mapped tasks, map_index is also part of the identity, and the public API exposes a separate mapped task instance endpoint for that case.

As implemented, airflowctl tasks state can only query non-mapped task instances, so users have no way to get the state of a mapped task instance through this command. This also means it does not match legacy airflow tasks state, which supports --map-index.

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