sunank200 commented on code in PR #51592:
URL: https://github.com/apache/airflow/pull/51592#discussion_r2138651770


##########
airflow-core/src/airflow/utils/log/file_task_handler.py:
##########
@@ -180,15 +181,18 @@ def _interleave_logs(*logs: str | LogMessages) -> 
Iterable[StructuredLogMessage]
         last = msg
 
 
-def _ensure_ti(ti: TaskInstanceKey | TaskInstance, session) -> TaskInstance:
+def _ensure_ti(
+    ti: TaskInstanceKey | TaskInstance | TaskInstanceHistory, session
+) -> TaskInstance | TaskInstanceHistory:
     """
-    Given TI | TIKey, return a TI object.
+    Return a TaskInstance or TaskInstanceHistory for the given TI, TIKey, or 
TaskInstanceHistory.
 
-    Will raise exception if no TI is found in the database.
+    Raises AirflowException if no TI is found in the database.
     """
     from airflow.models.taskinstance import TaskInstance
+    from airflow.models.taskinstancehistory import TaskInstanceHistory
 
-    if isinstance(ti, TaskInstance):
+    if isinstance(ti, (TaskInstance, TaskInstanceHistory)):
         return ti
     val = (

Review Comment:
   The actual fallback from latest TI → history TI lives up in the public-log 
route:
   - GET /logs first runs in 
https://github.com/apache/airflow/blob/67b7226133330559f0844cb11c7f8f9408cd4910/airflow-core/src/airflow/api_fastapi/core_api/routes/public/log.py#L108
   - only if that returns None does it run 
   
https://github.com/apache/airflow/blob/67b7226133330559f0844cb11c7f8f9408cd4910/airflow-core/src/airflow/api_fastapi/core_api/routes/public/log.py#L123
   
    Once you’ve got either a latest TI or a TIHistory, you hand it to 
FileTaskHandler unchanged.



-- 
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