kacpermuda commented on code in PR #75328:
URL: https://github.com/apache/airflow/pull/75328#discussion_r4390366862
##########
providers/openlineage/src/airflow/providers/openlineage/utils/utils.py:
##########
@@ -1209,17 +1209,56 @@ def get_rendered_map_index(ti: TaskInstance |
RuntimeTaskInstance) -> str | None
return getattr(ti, "rendered_map_index", None)
def __init__(
- self, obj, position: TaskInstancePosition | None = None, dag: Any =
None, dag_run: Any = None
+ self,
+ obj,
+ position: TaskInstancePosition | None = None,
+ dag: Any = None,
+ dag_run: Any = None,
+ end_date: datetime.datetime | None = None,
):
# Pass the position when the caller has already placed the task
instance, e.g. from its stored region or
# with get_task_instance_position; it is then used as is.
self._position = position
# A stored task instance's bundle comes from these, as the worker's
does, without a query
self._dag = dag
self._dag_run = dag_run
+ # The end date a terminal event is timed with, used when the task
instance carries none, as a skipped
+ # Airflow 3 runtime task instance doesn't before Airflow 3.4.
+ self._end_date = end_date
super().__init__(obj)
+ def _get_end_date(self) -> datetime.datetime | None:
+ if isinstance(end_date := getattr(self.obj, "end_date", None),
datetime.datetime):
+ return end_date
+ return self._end_date
+
+ def _get_duration(
+ self, start_date: datetime.datetime | None, end_date:
datetime.datetime | None
+ ) -> float | None:
+ # The stored duration is what the UI shows, so it wins. A runtime task
instance has none -- the API
+ # server computes it after the listener ran.
+ if (duration := getattr(self.obj, "duration", None)) is not None:
Review Comment:
Good catch. I took your suggestion. The stored `duration` is now used only
when the task instance also has an `end_date`. Without one, the duration is
computed from `start_date` and the end date passed in, or left out. So try 2's
START no longer carries try 1's duration. I added test cases for a leftover
duration without an `end_date`, with and without an end date passed in.
--
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]