Skip to content

Support --map-index in airflowctl tasks state#68776

Open
IamJasonBian wants to merge 7 commits into
apache:mainfrom
IamJasonBian:airflowctl-tasks-state-map-index
Open

Support --map-index in airflowctl tasks state#68776
IamJasonBian wants to merge 7 commits into
apache:mainfrom
IamJasonBian:airflowctl-tasks-state-map-index

Conversation

@IamJasonBian

@IamJasonBian IamJasonBian commented Jun 19, 2026

Copy link
Copy Markdown

Description

Adds a tasks state command to airflowctl and supports --map-index so the
state of a specific mapped task instance can be retrieved through the CLI:

airflowctl tasks state --dag-id=example_bash_operator \
  --dag-run-id="manual__..." --task-id=runme_0 [--map-index=N]

Also fixes the airflowctl integration test that exercised this area: it had
invoked the auto-generated taskinstances get command with --dag-id/
--dag-run-id/--task-id flags, which that command does not accept (it takes
positional args), causing argparse to exit 2. The entry now uses tasks state
(flags) to cover the new command, plus a correctly-formed positional
taskinstances get entry so both commands are exercised.

Testing

Set up localhost:8080

Ran below after toggling in UI

airflowctl tasks state
  --dag-id=example_bash_operator
  --dag-run-id="manual__2026-06-19T20:58:0
  8.871418+00:00" --task-id=runme_0 -> SUCCESS and FAIL states

 airflowctl tasks state
  --dag-id=example_bash_operator
  --dag-run-id="manual__2026-06-19T20:58:0
  8.871418+00:00" --task-id=this_will_skip -> SKIPPED

airflowctl tasks state
  --dag-id=example_bash_operator
  --dag-run-id="manual__2026-06-19T20:58:0
  8.871418+00:00" --task-id=nope_task -> not_found

airflowctl tasks state
  --dag-id=example_bash_operator
  --dag-run-id="manual__2026-06-19T20:58:0
  8.871418+00:00" --task-id=runme_0 -> not_found
  --map-index=0

  airflowctl tasks state
  --dag-id=example_bash_operator --dag-run
  -id="manual__2025-10-04T20:38:46+00:00"
  --task-id=runme_0 -> not_found

Reran CI locally


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

Generated-by: Claude Code (Opus 4.8) following the guidelines

hyungryuk and others added 6 commits May 11, 2026 00:09
  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
Allow `airflowctl tasks state` to query mapped task instances, matching
the legacy `airflow tasks state --map-index` behaviour. When the flag is
non-negative the mapped task instance endpoint is called; otherwise the
existing unmapped endpoint is used. The `taskinstances get` auto-generated
command also gains optional mapped-instance support via the same
`map_index` parameter on `TaskInstancesOperations.get`.
The integration test invoked `taskinstances get` with `--dag-id`/`--dag-run-id`/
`--task-id` flags, but that auto-generated command takes positional arguments, so
argparse exited with code 2 and the test failed. The flag syntax belongs to the
new `tasks state` command, which had no integration coverage at all.

Point the entry at `tasks state` (flags) to cover the new command, and add a
correctly-formed `taskinstances get` entry using positional args so both commands
are exercised.

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.

Do you think it's also worth adding a test to the test_operations.py file for the get command? The tests you added only seem to cover tasks state.

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.

3 participants