hussein-awala commented on code in PR #30641:
URL: https://github.com/apache/airflow/pull/30641#discussion_r1167280097
##########
airflow/models/xcom_arg.py:
##########
@@ -309,11 +310,19 @@ def zip(self, *others: XComArg, fillvalue: Any = NOTSET)
-> ZipXComArg:
return super().zip(*others, fillvalue=fillvalue)
def get_task_map_length(self, run_id: str, *, session: Session) -> int |
None:
+ from airflow.models.taskinstance import TaskInstance
from airflow.models.taskmap import TaskMap
from airflow.models.xcom import XCom
task = self.operator
if isinstance(task, MappedOperator):
+ state_query = session.query(TaskInstance.state).filter(
+ TaskInstance.dag_id == task.dag_id,
+ TaskInstance.run_id == run_id,
+ TaskInstance.task_id == task.task_id,
+ )
+ if any(state in State.unfinished for state, in state_query):
+ return None # Not all of the expanded tis are done yet.
Review Comment:
Why not getting the count of not finished tasks or the first one if it
exists instead of loading all the mapped tasks from the db and doing it with
python?
something like:
```suggestion
unfinished_ti = session.query(TaskInstance).filter(
TaskInstance.dag_id == task.dag_id,
TaskInstance.run_id == run_id,
TaskInstance.task_id == task.task_id,
TaskInstance.state.in_(State.unfinished),
).first()
if unfinished_ti is not None:
return None # Not all of the expanded tis are done yet.
```
--
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]