You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "sunank200 (via GitHub)" <gi...@apache.org> on 2025/06/10 17:43:54 UTC
[PR] Support TaskInstanceHistory in log handlers [airflow]
sunank200 opened a new pull request, #51592:
URL: https://github.com/apache/airflow/pull/51592
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
This change fixes the public log API to fully support `TaskInstanceHistory` by adding an `id` alias, a `get_dagrun()` helper to `TaskInstanceHistory`. This also updates `FileTaskHandler` to recognise history objects, and fixes the missing `try_number filter` in the FastAPI route so that retry task logs can be fetched correctly.
I have tested it by updating `log_filename_template = dag_id={{ ti.id }}/run_id={{ ti.run_id }}/task_id={{ ti.task_id }}/{%% if ti.map_index >= 0 %%}map_index={{ ti.map_index }}/{%% endif %%}attempt={{ try_number|default(ti.try_number) }}.log` and ran the task, then cleared the task instance and checked the log.
<img width="1728" alt="Screenshot 2025-06-10 at 11 28 19 PM" src="https://github.com/user-attachments/assets/2a150dad-7fb8-4d83-bb43-130afa54134c" />
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
closes: [#51525](https://github.com/apache/airflow/issues/51525)
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support TaskInstanceHistory in log handlers [airflow]
Posted by "sunank200 (via GitHub)" <gi...@apache.org>.
sunank200 commented on code in PR #51592:
URL: https://github.com/apache/airflow/pull/51592#discussion_r2138649191
##########
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:
@jedcunningham `_ensure_ti` doesn't find the right task instance or task instance history - it’s just a normalisation step inside the `FileTaskHandler` so that, no matter whether you passed in:
1. latest taskInstance
2. taskInstanceKey
3. taskInstanceHistory
You end up with an object that has `.id`, `.try_number`, and `.get_dagrun()`, which is all _render_filename needs.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support TaskInstanceHistory in log handlers [airflow]
Posted by "sunank200 (via GitHub)" <gi...@apache.org>.
sunank200 commented on code in PR #51592:
URL: https://github.com/apache/airflow/pull/51592#discussion_r2138672317
##########
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:
This code path ensures we only hit the TaskInstanceHistory table when there’s no latest TaskInstance for the requested try.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support TaskInstanceHistory in log handlers [airflow]
Posted by "sunank200 (via GitHub)" <gi...@apache.org>.
sunank200 commented on code in PR #51592:
URL: https://github.com/apache/airflow/pull/51592#discussion_r2140528710
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/log.py:
##########
@@ -112,6 +112,7 @@ def get_log(
TaskInstance.dag_id == dag_id,
TaskInstance.run_id == dag_run_id,
TaskInstance.map_index == map_index,
+ TaskInstance.try_number == try_number,
Review Comment:
Yup. That's the reason.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support TaskInstanceHistory in log handlers [airflow]
Posted by "vatsrahul1001 (via GitHub)" <gi...@apache.org>.
vatsrahul1001 merged PR #51592:
URL: https://github.com/apache/airflow/pull/51592
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support TaskInstanceHistory in log handlers [airflow]
Posted by "sunank200 (via GitHub)" <gi...@apache.org>.
sunank200 commented on code in PR #51592:
URL: https://github.com/apache/airflow/pull/51592#discussion_r2138649191
##########
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:
@jedcunningham `_ensure_ti` isn’t meant to be a “find me the right row” function for both tables - it’s just a normalisation step inside the `FileTaskHandler` so that, no matter whether you passed in:
1. a latest TaskInstance
2. a TaskInstanceKey
3. a TaskInstanceHistory
You end up with an object that has `.id`, `.try_number`, and `.get_dagrun()`, which is all _render_filename needs.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support TaskInstanceHistory in log handlers [airflow]
Posted by "dstandish (via GitHub)" <gi...@apache.org>.
dstandish commented on code in PR #51592:
URL: https://github.com/apache/airflow/pull/51592#discussion_r2138483596
##########
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:
i suppose it depends on the context. in execution context, should be fine?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support TaskInstanceHistory in log handlers [airflow]
Posted by "sunank200 (via GitHub)" <gi...@apache.org>.
sunank200 commented on code in PR #51592:
URL: https://github.com/apache/airflow/pull/51592#discussion_r2138649191
##########
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:
@jedcunningham `_ensure_ti` isn’t meant to be a “find me the right row” function for both tables - it’s just a normalisation step inside the `FileTaskHandler` so that, no matter whether you passed in:
1. a live TaskInstance
2. a TaskInstanceKey
3. a TaskInstanceHistory
You end up with an object that has `.id`, `.try_number`, and `.get_dagrun()`, which is all _render_filename needs.
##########
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:
@jedcunningham `_ensure_ti` isn’t meant to be a “find me the right row” function for both tables - it’s just a normalisation step inside the `FileTaskHandler` so that, no matter whether you passed in:
1. a live TaskInstance
2. a TaskInstanceKey
3. a TaskInstanceHistory
You end up with an object that has `.id`, `.try_number`, and `.get_dagrun()`, which is all _render_filename needs.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support TaskInstanceHistory in log handlers [airflow]
Posted by "sunank200 (via GitHub)" <gi...@apache.org>.
sunank200 commented on code in PR #51592:
URL: https://github.com/apache/airflow/pull/51592#discussion_r2139721714
##########
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:
I have removed `_ensure_ti` helper and accepted `TaskInstanceHistory` in log handlers and reader.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support TaskInstanceHistory in log handlers [airflow]
Posted by "sunank200 (via GitHub)" <gi...@apache.org>.
sunank200 commented on code in PR #51592:
URL: https://github.com/apache/airflow/pull/51592#discussion_r2138649191
##########
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:
@jedcunningham `_ensure_ti` isn’t meant to be a “find me the right row” function for both tables - it’s just a normalisation step inside the `FileTaskHandler` so that, no matter whether you passed in:
1. latest TaskInstance
2. TaskInstanceKey
3.. TaskInstanceHistory
You end up with an object that has `.id`, `.try_number`, and `.get_dagrun()`, which is all _render_filename needs.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support TaskInstanceHistory in log handlers [airflow]
Posted by "jedcunningham (via GitHub)" <gi...@apache.org>.
jedcunningham commented on code in PR #51592:
URL: https://github.com/apache/airflow/pull/51592#discussion_r2138478586
##########
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:
Is only querying TI the right behavior? Should this also fall back to history to get the right try? Just setting the try on the TI feels wrong.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support TaskInstanceHistory in log handlers [airflow]
Posted by "sunank200 (via GitHub)" <gi...@apache.org>.
sunank200 commented on PR #51592:
URL: https://github.com/apache/airflow/pull/51592#issuecomment-2962195968
> Related to #50175
>
> The #50175 try to fix on FastAPI side instead of FileTaskHandler, but introduce other error ( [#50175 (comment)](https://github.com/apache/airflow/pull/50175#issuecomment-2913881766) ).
I have tested for the error mentioned in the issue. It works fine with this change.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support TaskInstanceHistory in log handlers [airflow]
Posted by "sunank200 (via GitHub)" <gi...@apache.org>.
sunank200 commented on code in PR #51592:
URL: https://github.com/apache/airflow/pull/51592#discussion_r2138649191
##########
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:
@jedcunningham `_ensure_ti` doesn't find the right task instance or task instance history - it’s just a normalisation step inside the `FileTaskHandler` so that, no matter whether you passed in:
1. latest TaskInstance
2. TaskInstanceKey
3.. TaskInstanceHistory
You end up with an object that has `.id`, `.try_number`, and `.get_dagrun()`, which is all _render_filename needs.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support TaskInstanceHistory in log handlers [airflow]
Posted by "jedcunningham (via GitHub)" <gi...@apache.org>.
jedcunningham commented on code in PR #51592:
URL: https://github.com/apache/airflow/pull/51592#discussion_r2138712529
##########
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:
So, looking at this a bit closer, I'm not sure we even need this function any longer. We will always get a ti or tih to this. And typing through the whole process is also wrong, e.g. [read_log_stream](https://github.com/apache/airflow/blob/7ea915494a0065fb486567744fd63d60b7586070/airflow-core/src/airflow/utils/log/log_reader.py#L73) is typed to take ti, but also takes tih in practice.
Can you take a pass at cleaning this up?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support TaskInstanceHistory in log handlers [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on PR #51592:
URL: https://github.com/apache/airflow/pull/51592#issuecomment-2968719084
> Overall, looks good. Are other task handlers impacted by these typing changes? If so, probably can be addressed in a follow up as they'd be in providers...
IMO, we don't need to adapt TIH type hit for other provider-based task handlers, as most of them already adapted to RemoteIO interface ( which use `RuntimeTaskInstanceProtocol` as type annotation )
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support TaskInstanceHistory in log handlers [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #51592:
URL: https://github.com/apache/airflow/pull/51592#discussion_r2140366141
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/log.py:
##########
@@ -112,6 +112,7 @@ def get_log(
TaskInstance.dag_id == dag_id,
TaskInstance.run_id == dag_run_id,
TaskInstance.map_index == map_index,
+ TaskInstance.try_number == try_number,
Review Comment:
Nice catch, I think this is the root cause of #50175 error.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support TaskInstanceHistory in log handlers [airflow]
Posted by "sunank200 (via GitHub)" <gi...@apache.org>.
sunank200 commented on PR #51592:
URL: https://github.com/apache/airflow/pull/51592#issuecomment-2968889328
> > Overall, looks good. Are other task handlers impacted by these typing changes? If so, probably can be addressed in a follow up as they'd be in providers...
>
> IMO, we don't need to adapt TIH type hit for other provider-based task handlers, as most of them already adapted to RemoteIO interface ( which use `RuntimeTaskInstanceProtocol` as type annotation )
I can do a follow-up PR if required.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support TaskInstanceHistory in log handlers [airflow]
Posted by "dstandish (via GitHub)" <gi...@apache.org>.
dstandish commented on code in PR #51592:
URL: https://github.com/apache/airflow/pull/51592#discussion_r2138485378
##########
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:
but yeah why is it setting try number 🤔
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support TaskInstanceHistory in log handlers [airflow]
Posted by "sunank200 (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org