You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by am...@apache.org on 2026/04/28 09:25:56 UTC

(airflow) branch v3-2-test updated: [v3-2-test] Fix scheduler UniqueViolation crash on downgrade from 3.2.0 to 3.1.x (#65688) (#66003)

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

amoghrajesh pushed a commit to branch v3-2-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v3-2-test by this push:
     new f6f86764a9d [v3-2-test] Fix scheduler UniqueViolation crash on downgrade from 3.2.0 to 3.1.x (#65688) (#66003)
f6f86764a9d is described below

commit f6f86764a9d0333b4989f6ed9044ba49ccbf2cdb
Author: Amogh Desai <am...@gmail.com>
AuthorDate: Tue Apr 28 14:55:47 2026 +0530

    [v3-2-test] Fix scheduler UniqueViolation crash on downgrade from 3.2.0 to 3.1.x (#65688) (#66003)
    
    (cherry picked from commit 635896843794b83c4dffef2bccbb3bf45d0c2a25)
---
 .../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"
+    )