xBis7 commented on code in PR #71737:
URL: https://github.com/apache/airflow/pull/71737#discussion_r3864687633
##########
airflow-core/src/airflow/ti_deps/dep_context.py:
##########
@@ -107,20 +107,22 @@ class DepContext:
fresh empty dict, so they would neither read the memo nor warm it for
anything else.
"""
- def ensure_finished_tis(self, dag_run: DagRun, session: Session) ->
list[TaskInstance]:
+ def ensure_finished_tis(self, dag_run: DagRun, session: Session) ->
list[TaskInstance | FinishedTI]:
"""
Ensure finished_tis is populated if it's currently None, which allows
running tasks without dag_run.
:param dag_run: The DagRun for which to find finished tasks
:return: A list of all the finished tasks of this DAG and logical_date
"""
+ finished_tis: list[TaskInstance | FinishedTI]
if self.finished_tis is None:
- finished_tis = dag_run.get_task_instances(state=State.finished,
session=session)
- for ti in finished_tis:
+ fetched = dag_run.get_task_instances(state=State.finished,
session=session)
+ for ti in fetched:
Review Comment:
The query result is `list[TaskInstance]` but the method returns
`list[TaskInstance | FinishedTI]`.
So we have to create a new list with the union type, otherwise mypy will
complain about the assignment.
We could keep a single `finished_tis` assignment but we would still need the
`list()` conversion and the current code
```
finished_tis = list(fetched)
```
is easier to read than
```
finished_tis = list(finished_tis)
```
--
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]