Skip to content

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

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

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

Conversation

@IamJasonBian
Copy link
Copy Markdown

Stacked on top of #66202 — opening as a draft so the follow-up is visible while #66202 is still in review.

Addresses @parkhojeong's CHANGES_REQUESTED feedback on #66202: the new airflowctl tasks state command currently can't query a mapped task instance, so it doesn't match legacy airflow tasks state --map-index. The Airflow REST API exposes a separate path-parameter endpoint for mapped instances:

  • unmapped: GET /api/v2/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}
  • mapped:   GET /api/v2/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}/{map_index}

Hitting the unmapped endpoint for a mapped TI returns a 404 with the message "Task instance is mapped, add the map_index value to the URL", so today the command just hard-fails on any mapped task.

Changes (top commit only — 7156ab6)

  • TaskInstancesOperations.get now accepts an optional map_index and routes to the mapped endpoint when it's non-negative. Sentinel uses the existing int = None # type: ignore pattern from XComOperations so the auto-generated taskinstances get command continues to work when the flag is omitted.
  • New --map-index flag on airflowctl tasks state (default -1, matching legacy airflow tasks state semantics).
  • Three new parametrized unit tests for the mapped path (map_index ∈ {0, 1, 7}); existing unmapped tests untouched.
  • The auto-generated taskinstances get command also gains optional --map-index support transparently.

Stacking note

The bottom two commits in this branch (cfdb6617, f1e90629) belong to @hyungryuk from #66202 — they're only here because #66202 hasn't merged yet. Once #66202 lands, this PR will rebase to the single 7156ab6 commit (52 +/3 - across 4 files) and come out of draft.

If @hyungryuk would prefer to fold the map-index support directly into #66202 instead of landing it as a follow-up, I'm happy to close this and push the diff there as a suggested change.

related: #66174
follows: #66202


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

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

@boring-cyborg
Copy link
Copy Markdown

boring-cyborg Bot commented May 7, 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

@hyungryuk
Copy link
Copy Markdown

@IamJasonBian Thanks! I’ve merged your suggested changes into my PR. The branch is now updated with the additional commits. (d76a2fc)

@IamJasonBian IamJasonBian marked this pull request as ready for review May 8, 2026 15:42
@potiuk
Copy link
Copy Markdown
Member

potiuk commented May 11, 2026

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

  • Pre-commit / static checks — Failing: CI image checks / Build documentation (--spellcheck-only). The PR likely introduces a word the spellchecker doesn't recognize — add it to docs/spelling_wordlist.txt (alphabetical order) or rephrase. 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.


Drafted-by: Claude Code (Opus 4.7); reviewed by @potiuk before posting

hyungryuk and others added 3 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`.
@IamJasonBian IamJasonBian force-pushed the airflowctl-tasks-state-map-index branch from 3b15121 to 9f9eb16 Compare May 11, 2026 04:09
@IamJasonBian
Copy link
Copy Markdown
Author

IamJasonBian commented May 11, 2026

@potiuk thanks! - added to docs/spelling_wordlist.txt‎ and rebased

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