Skip to content

Conversation

@Subham-KRLX
Copy link
Contributor

@Subham-KRLX Subham-KRLX commented Dec 31, 2025

Fix the incorrect Log and TaskInstance join query

This PR addresses the issue: #59965.

The Log.task_instance relationship in airflow/models/log.py has been updated to use a strict join on the following fields:

  • dag_id
  • task_id
  • run_id
  • map_index

This change ensures that log entries are correctly associated with their corresponding task instances, resolving an issue where the relationship was previously defined with a primaryjoin that only checked for matching
task_id.

@henry3260
Copy link
Contributor

Thanks for the pr!
You should pass the static check locally.

@Subham-KRLX
Copy link
Contributor Author

I think now its good to go.

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.

I think now its good to go.

We still encounter the same ruff formatting static check failure: https://github.com/apache/airflow/actions/runs/20718428075/job/59476214319?pr=59973

@Subham-KRLX
Copy link
Contributor Author

Fixed the ruff formatting issue by flattening the primaryjoin definition. Validated locally with ruff==0.14.10 and checks are passing now.

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.

Thanks for the update, LGTM.

@jason810496 jason810496 added the backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch label Jan 7, 2026
@potiuk potiuk linked an issue Jan 7, 2026 that may be closed by this pull request
2 tasks
@potiuk potiuk added this to the Airflow 3.1.6 milestone Jan 7, 2026
@potiuk potiuk merged commit 91af86e into apache:main Jan 7, 2026
71 checks passed
github-actions bot pushed a commit that referenced this pull request Jan 7, 2026
* Fix incorrect Log and TaskInstance join query

* Fix log task instance join foreign keys and remove stray newsfragment

* Remove unused task variable assignments in test_log_task_instance_join_correctness

* Fix CI failures and address reviewer comments: revert unrelated doc changes, clean up tests, add Mapped type hints to Log relationships, and run ruff formatting

* Restore newsfragment and fix missing import in log.py

* Fix reviewer feedback: add license, move imports, and fix newsfragments

* Fix ruff static check failure in log.py

* Flatten primaryjoin definition to fix formatting

* Fix newsfragments per review: restore 58337 and remove 59965

* Remove unused import in log.py

---------
(cherry picked from commit 91af86e)

Co-authored-by: Subham <subhamsangwan26@gmail.com>
Co-authored-by: Jason(Zhe-You) Liu <68415893+jason810496@users.noreply.github.com>
@github-actions
Copy link

github-actions bot commented Jan 7, 2026

Backport successfully created: v3-1-test

Status Branch Result
v3-1-test PR Link

jscheffl pushed a commit that referenced this pull request Jan 7, 2026
* [v3-1-test] Fix log task instance join (#59973)

* Fix incorrect Log and TaskInstance join query

* Fix log task instance join foreign keys and remove stray newsfragment

* Remove unused task variable assignments in test_log_task_instance_join_correctness

* Fix CI failures and address reviewer comments: revert unrelated doc changes, clean up tests, add Mapped type hints to Log relationships, and run ruff formatting

* Restore newsfragment and fix missing import in log.py

* Fix reviewer feedback: add license, move imports, and fix newsfragments

* Fix ruff static check failure in log.py

* Flatten primaryjoin definition to fix formatting

* Fix newsfragments per review: restore 58337 and remove 59965

* Remove unused import in log.py

---------
(cherry picked from commit 91af86e)

Co-authored-by: Subham <subhamsangwan26@gmail.com>
Co-authored-by: Jason(Zhe-You) Liu <68415893+jason810496@users.noreply.github.com>

* Fix backport: Remove Mapped type hints for SQLAlchemy 1.x compatibility

* Fix unused import in log.py

* Update airflow-core/src/airflow/models/log.py

---------

Co-authored-by: Jason(Zhe-You) Liu <68415893+jason810496@users.noreply.github.com>
Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
chirodip98 pushed a commit to chirodip98/airflow-contrib that referenced this pull request Jan 9, 2026
* Fix incorrect Log and TaskInstance join query

* Fix log task instance join foreign keys and remove stray newsfragment

* Remove unused task variable assignments in test_log_task_instance_join_correctness

* Fix CI failures and address reviewer comments: revert unrelated doc changes, clean up tests, add Mapped type hints to Log relationships, and run ruff formatting

* Restore newsfragment and fix missing import in log.py

* Fix reviewer feedback: add license, move imports, and fix newsfragments

* Fix ruff static check failure in log.py

* Flatten primaryjoin definition to fix formatting

* Fix newsfragments per review: restore 58337 and remove 59965

* Remove unused import in log.py

---------

Co-authored-by: Jason(Zhe-You) Liu <68415893+jason810496@users.noreply.github.com>
stegololz pushed a commit to stegololz/airflow that referenced this pull request Jan 9, 2026
* Fix incorrect Log and TaskInstance join query

* Fix log task instance join foreign keys and remove stray newsfragment

* Remove unused task variable assignments in test_log_task_instance_join_correctness

* Fix CI failures and address reviewer comments: revert unrelated doc changes, clean up tests, add Mapped type hints to Log relationships, and run ruff formatting

* Restore newsfragment and fix missing import in log.py

* Fix reviewer feedback: add license, move imports, and fix newsfragments

* Fix ruff static check failure in log.py

* Flatten primaryjoin definition to fix formatting

* Fix newsfragments per review: restore 58337 and remove 59965

* Remove unused import in log.py

---------

Co-authored-by: Jason(Zhe-You) Liu <68415893+jason810496@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch kind:documentation provider:standard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect log and task instance join query based on task_id in eventLogs API

7 participants