uranusjr commented on code in PR #64133:
URL: https://github.com/apache/airflow/pull/64133#discussion_r3019765234


##########
airflow-core/src/airflow/cli/commands/task_command.py:
##########
@@ -203,7 +204,18 @@ def _get_ti(
                 f"TaskInstance for {dag.dag_id}, {task.task_id}, 
map={map_index} with "
                 f"run_id or logical_date of {logical_date_or_run_id!r} not 
found"
             )
-        # TODO: Validate map_index is in range?
+        if map_index >= 0:
+            try:
+                total = task.get_parse_time_mapped_ti_count()
+                if map_index >= total:
+                    raise ValueError(
+                        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.")

Review Comment:
   I think this should match the `get_needs_expansion` checks above. Either all 
of these should use ValueError or RuntimeError.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to