This is an automated email from the ASF dual-hosted git repository.

ephraimanierobi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new bcf51254380 Update TI.dag_version after dag/taskinstance clearing 
(#55180)
bcf51254380 is described below

commit bcf51254380209a9c2e260d0cf9407964ba9d012
Author: Ephraim Anierobi <[email protected]>
AuthorDate: Tue Sep 2 15:16:36 2025 +0100

    Update TI.dag_version after dag/taskinstance clearing (#55180)
    
    If run with latest bundle is selected during clear, then we should
    also update the TI.dag_version same way we updated dagrun. This is
    primarily for consistency in the UI
---
 airflow-core/src/airflow/models/taskinstance.py   | 2 ++
 airflow-core/tests/unit/models/test_cleartasks.py | 4 ++++
 2 files changed, 6 insertions(+)

diff --git a/airflow-core/src/airflow/models/taskinstance.py 
b/airflow-core/src/airflow/models/taskinstance.py
index 27a46b366dc..54432bf90ba 100644
--- a/airflow-core/src/airflow/models/taskinstance.py
+++ b/airflow-core/src/airflow/models/taskinstance.py
@@ -288,6 +288,8 @@ def clear_task_instances(
                         dr.created_dag_version_id = dag_version.id
                         dr.dag = dr_dag
                         dr.verify_integrity(session=session, 
dag_version_id=dag_version.id)
+                        for ti in dr.task_instances:
+                            ti.dag_version_id = dag_version.id
                 else:
                     dr_dag = scheduler_dagbag.get_dag_for_run(dag_run=dr, 
session=session)
                 if not dr_dag:
diff --git a/airflow-core/tests/unit/models/test_cleartasks.py 
b/airflow-core/tests/unit/models/test_cleartasks.py
index d0066fffe99..c44cdf5635e 100644
--- a/airflow-core/tests/unit/models/test_cleartasks.py
+++ b/airflow-core/tests/unit/models/test_cleartasks.py
@@ -717,7 +717,11 @@ class TestClearTasks:
             assert dr.created_dag_version_id == new_dag_version.id
             assert dr.bundle_version == new_dag_version.bundle_version
             assert TaskInstanceState.REMOVED in [ti.state for ti in 
dr.task_instances]
+            for ti in dr.task_instances:
+                assert ti.dag_version_id == new_dag_version.id
         else:
             assert dr.created_dag_version_id == old_dag_version.id
             assert dr.bundle_version == old_dag_version.bundle_version
             assert TaskInstanceState.REMOVED not in [ti.state for ti in 
dr.task_instances]
+            for ti in dr.task_instances:
+                assert ti.dag_version_id == old_dag_version.id

Reply via email to