Skip to content

Fix log task instance join#59973

Merged
potiuk merged 13 commits intoapache:mainfrom
Subham-KRLX:fix-log-task-instance-join
Jan 7, 2026
Merged

Fix log task instance join#59973
potiuk merged 13 commits intoapache:mainfrom
Subham-KRLX:fix-log-task-instance-join

Conversation

@Subham-KRLX
Copy link
Copy Markdown
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.

Comment thread providers/standard/docs/sensors/datetime.rst Outdated
@henry3260
Copy link
Copy Markdown
Contributor

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

Comment thread airflow-core/tests/unit/models/test_log.py Outdated
Comment thread airflow-core/tests/unit/models/test_log.py Outdated
Comment thread airflow-core/tests/unit/models/test_log.py
Comment thread airflow-core/tests/unit/models/test_log.py Outdated
@Subham-KRLX
Copy link
Copy Markdown
Contributor Author

I think now its good to go.

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

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

Comment thread airflow-core/newsfragments/58337.feature.rst Outdated
Comment thread airflow-core/newsfragments/59965.bugfix.rst Outdated
Copy link
Copy Markdown
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.

Comment thread airflow-core/src/airflow/models/log.py Outdated
@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
Copy Markdown
Contributor

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>
jhgoebbert pushed a commit to jhgoebbert/airflow_Owen-CH-Leung that referenced this pull request Feb 8, 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>
Subham-KRLX added a commit to Subham-KRLX/airflow that referenced this pull request Mar 4, 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>
Ankurdeewan pushed a commit to Ankurdeewan/airflow that referenced this pull request Mar 15, 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

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