Skip to content

Validate map_index range in CLI commands - #62626

Merged
potiuk merged 5 commits into
apache:mainfrom
Leondon9:fix/60463-validate-map-index-range
Mar 11, 2026
Merged

potiuk merged 5 commits into
apache:mainfrom
Leondon9:fix/60463-validate-map-index-range

Conversation

@Leondon9

Copy link
Copy Markdown
Contributor

Validate map_index range when creating task instances via CLI commands
(tasks render, tasks test, etc.) to provide a clear error instead of
silently proceeding with an invalid index.

Changes:

  • In _get_ti(), call task.get_parse_time_mapped_ti_count() to check
    that map_index is within [0, count) when a non-negative index is
    supplied.
  • For dynamically mapped tasks (XCom-based), catch NotFullyPopulated
    / NotMapped and skip validation since the count is not available at
    parse time.
  • Add 3 tests: out-of-range error, boundary success, dynamic mapping
    skip.

closes: #60463


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

following the guidelines

@boring-cyborg

boring-cyborg Bot commented Feb 28, 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 (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
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: [email protected]
    Slack: https://s.apache.org/airflow-slack

When a user passes a map_index to CLI commands like `tasks render` or
`tasks test`, validate that it falls within the parse-time mapped count.
This gives a clear error message instead of silently proceeding with an
invalid index. For dynamically mapped tasks (XCom-based), the validation
is skipped since the count is not available at parse time.

closes: apache#60463

Co-Authored-By: claude-flow <[email protected]>
@Leondon9
Leondon9 force-pushed the fix/60463-validate-map-index-range branch from a569059 to 7ad1cfd Compare February 28, 2026 17:50

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

Approach is sound. I have left a few comments. Overall, this a well-justified, tightly scoped change.

@Leondon9

Leondon9 commented Mar 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @SameerMesiah97 for the review!

Comment 1 (NotFullyPopulated/NotMapped split): Good point — NotMapped is indeed a user input error, not an ambiguous runtime state. I've split them so NotMapped raises a clear ValueError.

Comment 2 (test pattern): Makes sense, pytest.raises is the standard pattern. I've updated the test to use pytest.raises(Exception) with a negative assertion on the error message.

Both changes pushed.

Leondon9 and others added 2 commits March 1, 2026 16:17
Split the except block so NotMapped raises a ValueError instead of
being silently ignored alongside NotFullyPopulated. Also switch the
dynamic-mapping test to the standard pytest.raises pattern.

Co-Authored-By: claude-flow <[email protected]>
@Leondon9

Leondon9 commented Mar 1, 2026

Copy link
Copy Markdown
Contributor Author

The Integration core redis job failed again — same flaky test_scheduler_exits_gracefully_in_the_middle_of_the_first_task (OpenTelemetry span assertion). Unrelated to this PR's changes. All other checks pass.

Leondon9 and others added 2 commits March 1, 2026 21:19
Replace `rich.print(pools_list)` with `AirflowConsole().print_as()` so
non-JSON export formats (table, yaml, plain) are rendered consistently
with other airflow-ctl commands. Add test verifying the delegation.

Co-Authored-By: claude-flow <[email protected]>
@potiuk
potiuk merged commit a6ea6f9 into apache:main Mar 11, 2026
71 checks passed
dominikhei pushed a commit to dominikhei/airflow that referenced this pull request Mar 11, 2026
* Validate map_index range in CLI commands

When a user passes a map_index to CLI commands like `tasks render` or
`tasks test`, validate that it falls within the parse-time mapped count.
This gives a clear error message instead of silently proceeding with an
invalid index. For dynamically mapped tasks (XCom-based), the validation
is skipped since the count is not available at parse time.

closes: apache#60463

Co-Authored-By: claude-flow <[email protected]>

* Raise clear error for map_index on non-mapped tasks

Split the except block so NotMapped raises a ValueError instead of
being silently ignored alongside NotFullyPopulated. Also switch the
dynamic-mapping test to the standard pytest.raises pattern.

Co-Authored-By: claude-flow <[email protected]>

* Fix ruff format: collapse single-line raise ValueError

Co-Authored-By: claude-flow <[email protected]>

* Use AirflowConsole for non-JSON pool export output

Replace `rich.print(pools_list)` with `AirflowConsole().print_as()` so
non-JSON export formats (table, yaml, plain) are rendered consistently
with other airflow-ctl commands. Add test verifying the delegation.

Co-Authored-By: claude-flow <[email protected]>

* Revert "Use AirflowConsole for non-JSON pool export output"

This reverts commit 5dc87ee.

---------

Co-authored-by: claude-flow <[email protected]>
Pyasma pushed a commit to Pyasma/airflow that referenced this pull request Mar 13, 2026
* Validate map_index range in CLI commands

When a user passes a map_index to CLI commands like `tasks render` or
`tasks test`, validate that it falls within the parse-time mapped count.
This gives a clear error message instead of silently proceeding with an
invalid index. For dynamically mapped tasks (XCom-based), the validation
is skipped since the count is not available at parse time.

closes: apache#60463

Co-Authored-By: claude-flow <[email protected]>

* Raise clear error for map_index on non-mapped tasks

Split the except block so NotMapped raises a ValueError instead of
being silently ignored alongside NotFullyPopulated. Also switch the
dynamic-mapping test to the standard pytest.raises pattern.

Co-Authored-By: claude-flow <[email protected]>

* Fix ruff format: collapse single-line raise ValueError

Co-Authored-By: claude-flow <[email protected]>

* Use AirflowConsole for non-JSON pool export output

Replace `rich.print(pools_list)` with `AirflowConsole().print_as()` so
non-JSON export formats (table, yaml, plain) are rendered consistently
with other airflow-ctl commands. Add test verifying the delegation.

Co-Authored-By: claude-flow <[email protected]>

* Revert "Use AirflowConsole for non-JSON pool export output"

This reverts commit 5dc87ee.

---------

Co-authored-by: claude-flow <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate map_index range when creating task instances via CLI

3 participants