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

amoghrajesh 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 63589684379 Fix scheduler UniqueViolation crash on downgrade from 
3.2.0 to 3.1.x (#65688)
63589684379 is described below

commit 635896843794b83c4dffef2bccbb3bf45d0c2a25
Author: Amogh Desai <[email protected]>
AuthorDate: Tue Apr 28 13:16:19 2026 +0530

    Fix scheduler UniqueViolation crash on downgrade from 3.2.0 to 3.1.x 
(#65688)
---
 .../versions/0107_3_2_0_add_partition_fields_to_dag.py       | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git 
a/airflow-core/src/airflow/migrations/versions/0107_3_2_0_add_partition_fields_to_dag.py
 
b/airflow-core/src/airflow/migrations/versions/0107_3_2_0_add_partition_fields_to_dag.py
index 52abaee3560..eda8aed183d 100644
--- 
a/airflow-core/src/airflow/migrations/versions/0107_3_2_0_add_partition_fields_to_dag.py
+++ 
b/airflow-core/src/airflow/migrations/versions/0107_3_2_0_add_partition_fields_to_dag.py
@@ -62,3 +62,15 @@ def downgrade():
             batch_op.drop_column("next_dagrun_partition_date")
         with op.batch_alter_table("dag_run", schema=None) as batch_op:
             batch_op.drop_column("partition_date")
+
+    # When downgrading from 3.2.0 to 3.1.x, the run_id generation semantics 
change:
+    # 3.2.0 generates run_id from run_after (data interval end),
+    # 3.1.x generates run_id from next_dagrun (logical date / data interval 
start).
+    # If next_dagrun/next_dagrun_create_after are left pointing at values set 
by 3.2.0,
+    # the 3.1.x scheduler will try to create runs with run_ids that already 
exist in
+    # dag_run, causing DB insert violation. Nulling these fields forces the 
3.1.x
+    # scheduler to recalculate them from the last completed run using 3.1.x 
semantics.
+    op.execute(
+        "UPDATE dag SET next_dagrun = NULL, next_dagrun_create_after = NULL, "
+        "next_dagrun_data_interval_start = NULL, next_dagrun_data_interval_end 
= NULL"
+    )

Reply via email to