Skip to content

Conversation

@sunank200
Copy link
Collaborator

@sunank200 sunank200 commented Jun 10, 2025

This change fixes the 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.

Screenshot 2025-06-10 at 11 28 19 PM

closes: #51525


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
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.

@sunank200 sunank200 requested a review from dstandish June 10, 2025 17:44
@sunank200 sunank200 force-pushed the fix-try-number-for-log-template branch 2 times, most recently from 3a151e7 to 67b7226 Compare June 10, 2025 17:49
Copy link
Contributor

@dstandish dstandish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks ok to me

Copy link
Member

@jason810496 jason810496 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to #50175

The #50175 try to fix on FastAPI side instead of FileTaskHandler, but introduce other error ( #50175 (comment) ).

@sunank200 sunank200 force-pushed the fix-try-number-for-log-template branch 3 times, most recently from 6d22132 to e92a2a7 Compare June 11, 2025 10:02
@sunank200
Copy link
Collaborator Author

Related to #50175

The #50175 try to fix on FastAPI side instead of FileTaskHandler, but introduce other error ( #50175 (comment) ).

I have tested for the error mentioned in the issue. It works fine with this change.

@sunank200 sunank200 requested a review from jedcunningham June 11, 2025 13:12
@sunank200 sunank200 force-pushed the fix-try-number-for-log-template branch from e92a2a7 to 4d624db Compare June 11, 2025 15:54
@sunank200 sunank200 force-pushed the fix-try-number-for-log-template branch from 4d624db to d0a94c3 Compare June 12, 2025 07:05
Copy link
Member

@jedcunningham jedcunningham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jason810496
Copy link
Member

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 )

@sunank200
Copy link
Collaborator Author

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.

@vatsrahul1001 vatsrahul1001 merged commit 5749e12 into apache:main Jun 13, 2025
97 checks passed
@vatsrahul1001 vatsrahul1001 deleted the fix-try-number-for-log-template branch June 13, 2025 04:46
RoyLee1224 pushed a commit to RoyLee1224/airflow that referenced this pull request Jun 13, 2025
Support TaskInstanceHistory in log handlers
choo121600 pushed a commit to choo121600/airflow that referenced this pull request Jun 14, 2025
Support TaskInstanceHistory in log handlers
kaxil pushed a commit that referenced this pull request Jul 2, 2025
Support TaskInstanceHistory in log handlers

(cherry picked from commit 5749e12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Retrieving logs for previous task attempts uses the wrong task instance ID

5 participants