This is an automated email from the ASF dual-hosted git repository.
shahar1 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new bbc448fc386 Fix task CLI map_index bounds validation (#64133)
bbc448fc386 is described below
commit bbc448fc3862fb2ee474fc2c33223f010eaf13a9
Author: Nandan <[email protected]>
AuthorDate: Sun Apr 19 10:49:07 2026 +0530
Fix task CLI map_index bounds validation (#64133)
---
airflow-core/src/airflow/cli/commands/task_command.py | 4 ++--
airflow-core/tests/unit/cli/commands/test_task_command.py | 11 +++++++----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/airflow-core/src/airflow/cli/commands/task_command.py
b/airflow-core/src/airflow/cli/commands/task_command.py
index b139459c9ee..df9c44910fa 100644
--- a/airflow-core/src/airflow/cli/commands/task_command.py
+++ b/airflow-core/src/airflow/cli/commands/task_command.py
@@ -207,14 +207,14 @@ def _get_ti(
try:
total = task.get_parse_time_mapped_ti_count()
if map_index >= total:
- raise ValueError(
+ raise RuntimeError(
f"map_index {map_index} is out of range. "
f"Task '{task.task_id}' has {total} mapped instance(s)
[0..{total - 1}]."
)
except NotFullyPopulated:
pass # Dynamic mapping — cannot validate at parse time
except NotMapped:
- raise ValueError(f"Task '{task.task_id}' is not mapped;
map_index must be -1.")
+ raise RuntimeError(f"Task '{task.task_id}' is not mapped;
map_index must be -1.")
dag_version = DagVersion.get_latest_version(dag.dag_id,
session=session)
if not dag_version:
# TODO: Remove this once DagVersion.get_latest_version is
guaranteed to return a DagVersion/raise
diff --git a/airflow-core/tests/unit/cli/commands/test_task_command.py
b/airflow-core/tests/unit/cli/commands/test_task_command.py
index a725fc5c006..b66384d5ad4 100644
--- a/airflow-core/tests/unit/cli/commands/test_task_command.py
+++ b/airflow-core/tests/unit/cli/commands/test_task_command.py
@@ -336,8 +336,8 @@ class TestCliTasks:
@pytest.mark.usefixtures("testing_dag_bundle")
def test_mapped_task_render_out_of_range_map_index(self):
- """Raise ValueError when map_index exceeds the parse-time mapped
count."""
- with pytest.raises(ValueError, match=r"map_index 5 is out of range.*3
mapped instance"):
+ """Raise RuntimeError when map_index exceeds the parse-time mapped
count."""
+ with pytest.raises(RuntimeError) as exc_info:
task_command.task_render(
self.parser.parse_args(
[
@@ -351,6 +351,9 @@ class TestCliTasks:
]
)
)
+ assert exc_info.value.args == (
+ "map_index 5 is out of range. Task 'consumer_literal' has 3 mapped
instance(s) [0..2].",
+ )
@pytest.mark.usefixtures("testing_dag_bundle")
def test_mapped_task_render_boundary_map_index(self):
@@ -379,8 +382,8 @@ class TestCliTasks:
# consumer depends on XCom from make_arg_lists, so parse-time count
# is not available. Validation should be skipped (NotFullyPopulated).
# The render may fail for other reasons, but not with our
- # "out of range" ValueError.
- with pytest.raises(Exception) as exc_info: # noqa: PT011
+ # "out of range" RuntimeError.
+ with pytest.raises(Exception, match=".*") as exc_info:
task_command.task_render(
self.parser.parse_args(
[