ashb commented on a change in pull request #21019:
URL: https://github.com/apache/airflow/pull/21019#discussion_r792451766
##########
File path: airflow/models/baseoperator.py
##########
@@ -1800,6 +1801,73 @@ def wait_for_downstream(self) -> bool:
def depends_on_past(self) -> bool:
return self.partial_kwargs.get("depends_on_past") or
self.wait_for_downstream
+ def expand_mapped_task(self, upstream_ti: "TaskInstance", session:
"Session" = NEW_SESSION) -> None:
+ """Create the mapped TaskInstances for mapped task."""
+ # TODO: support having multiuple mapped upstreams?
+ from airflow.models.taskmap import TaskMap
+ from airflow.settings import task_instance_mutation_hook
+
+ task_map_info_length: Optional[int] = (
+ session.query(TaskMap.length)
+ .filter_by(
+ dag_id=upstream_ti.dag_id,
+ task_id=upstream_ti.task_id,
+ run_id=upstream_ti.run_id,
+ map_index=upstream_ti.map_index,
+ )
+ .scalar()
+ )
+ if task_map_info_length is None:
+ # TODO: What would lead to this? How can this be better handled?
+ raise RuntimeError("mapped operator cannot be expanded; upstream
not found")
+ # TODO: Add db constraint to ensure this is never negative.
+
+ unmapped_ti: Optional[TaskInstance] = (
+ session.query(TaskInstance)
+ .filter(
+ TaskInstance.dag_id == upstream_ti.dag_id,
+ TaskInstance.run_id == upstream_ti.run_id,
+ TaskInstance.task_id == self.task_id,
+ TaskInstance.map_index == -1,
+ TaskInstance.state.in_(State.unfinished),
+ )
+ .one_or_none()
+ )
+
+ if unmapped_ti:
+ # The unmapped task instance still exists and is unfinished, i.e.
we
+ # haven't tried to run it before.
+ if task_map_info_length < 1:
+ # If the upstream maps this to a zero-length value, simply
marked the
+ # unmapped task instance as SKIPPED (if needed).
+ unmapped_ti.state = TaskInstanceState.SKIPPED
Review comment:
Done.
--
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]