Skip to content

Conversation

@tirkarthi
Copy link
Contributor

@tirkarthi tirkarthi commented Nov 22, 2025

Filtering by DagRun.run_id results in fetching other dagruns of same run_id which could be in running state with end_date as None. Filter by DagRun.id to get only the dagrun relevant and prune deadlines associated with it.

Closes #58560

@tirkarthi
Copy link
Contributor Author

For some reason session.merge is required for tests but the patch works without it in the scheduler with end_date set. Please add in if I am missing something in test setup.

@ferruzzi
Copy link
Contributor

You've said you were able to recreate the issue; I presume you've tested this change and it fixes the issue?

@tirkarthi
Copy link
Contributor Author

Yes, the tests also fail when the query is changed giving the traceback as reported in the issue. The issue can be reproduced with 2 dags with a deadline and task of time.sleep(10) and time.sleep(100) respectively
When dag1 completes it tries to prune deadline for dag2 of same run_id. This is fixed by using DagRun.id to get deadline associated with only the dagrun and avoids retrieving other dagruns of same run_id.

My question was that tests required session.merge but testing it manually in the UI with above setup didn't require it.

@ferruzzi
Copy link
Contributor

I'm a little scattered right now, just got back from vacation and getting pulled in a few directions. I THINK the issue is that the dag_maker fixture doesn't merge. Try the same tests but creating the DAG from scratch like some of the others in that file do. I'm pretty sure that was the fix when I ran into it in the past.

@ramitkataria
Copy link
Contributor

@amoghrajesh @potiuk can we please have this backported for 3.1.4 once it is merged?

Copy link
Contributor

@ramitkataria ramitkataria left a comment

Choose a reason for hiding this comment

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

Other than the current thread about the session.merge, looks good to me!

@tirkarthi tirkarthi added the backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch label Nov 29, 2025
@tirkarthi
Copy link
Contributor Author

I took some from help from AI and looked at test_dagrun_set_state_end_date which was testing end_date with same flow. It seems I need to add session.add(dag_run) so that the updates to the attribute are tracked. I removed the session.merge in core and adding session.add(dag_run) in tests seems to fix it. print(vars(inspect(dag_run1)), vars(session.identity_map)) before and after session.add was helpful.

https://docs.sqlalchemy.org/en/20/orm/session_state_management.html#session-object-states

@tirkarthi tirkarthi added this to the Airflow 3.1.4 milestone Nov 29, 2025
@ephraimbuddy ephraimbuddy added the type:bug-fix Changelog: Bug Fixes label Dec 1, 2025
Copy link
Contributor

@ferruzzi ferruzzi left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@potiuk
Copy link
Member

potiuk commented Dec 1, 2025

Make sense!

@potiuk potiuk merged commit c9d0fab into apache:main Dec 1, 2025
65 checks passed
github-actions bot pushed a commit that referenced this pull request Dec 1, 2025
…other dagruns of same run_id are not pruned. (#58574)

* Select deadlines by id so that deadlines associated with other dagruns of same run_id are not pruned.

* Track updates to dagrun attribute by session.add .
(cherry picked from commit c9d0fab)

Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>
@github-actions
Copy link

github-actions bot commented Dec 1, 2025

Backport successfully created: v3-1-test

Status Branch Result
v3-1-test PR Link

potiuk pushed a commit that referenced this pull request Dec 1, 2025
…other dagruns of same run_id are not pruned. (#58574) (#58910)

* Select deadlines by id so that deadlines associated with other dagruns of same run_id are not pruned.

* Track updates to dagrun attribute by session.add .
(cherry picked from commit c9d0fab)

Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>
ephraimbuddy pushed a commit that referenced this pull request Dec 3, 2025
…other dagruns of same run_id are not pruned. (#58574) (#58910)

* Select deadlines by id so that deadlines associated with other dagruns of same run_id are not pruned.

* Track updates to dagrun attribute by session.add .
(cherry picked from commit c9d0fab)

Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>
RoyLee1224 pushed a commit to RoyLee1224/airflow that referenced this pull request Dec 3, 2025
…s of same run_id are not pruned. (apache#58574)

* Select deadlines by id so that deadlines associated with other dagruns of same run_id are not pruned.

* Track updates to dagrun attribute by session.add .
Copilot AI pushed a commit to jason810496/airflow that referenced this pull request Dec 5, 2025
…s of same run_id are not pruned. (apache#58574)

* Select deadlines by id so that deadlines associated with other dagruns of same run_id are not pruned.

* Track updates to dagrun attribute by session.add .
itayweb pushed a commit to itayweb/airflow that referenced this pull request Dec 6, 2025
…s of same run_id are not pruned. (apache#58574)

* Select deadlines by id so that deadlines associated with other dagruns of same run_id are not pruned.

* Track updates to dagrun attribute by session.add .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scheduler pod crash because of Deadline set on DAG

5 participants