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

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

commit 220a7a4fe60a787b217f75def0a725625e155e86
Author: Kaxil Naik <[email protected]>
AuthorDate: Fri Aug 22 05:42:01 2025 +0100

    Fix MySQL UUID generation in task_instance migration (#54814)
    
    (cherry picked from commit 600716ffb97be0510773c3689faf4be7a6c8ffbd)
---
 RELEASE_NOTES.rst                                  |  1 +
 airflow-core/docs/img/airflow_erd.sha256           |  2 +-
 ...3_0_0_add_uuid_primary_key_to_task_instance_.py | 29 +++++++++++-----------
 reproducible_build.yaml                            |  4 +--
 4 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/RELEASE_NOTES.rst b/RELEASE_NOTES.rst
index 489bb61152b..43d07e4dc98 100644
--- a/RELEASE_NOTES.rst
+++ b/RELEASE_NOTES.rst
@@ -46,6 +46,7 @@ Bug Fixes
 - UI: Automatically switch to the triggered DAG run in Graph/Grid view when 
manually triggering a DAG run (#54336)
 - UI: Fix "Maximum update depth exceeded" errors in Task Log Preview by 
filtering out empty log entries (#54628)
 - Fix custom logging configuration failures preventing triggerer and scheduler 
startup with simple module paths (#54686)
+- Fix MySQL UUID generation in task_instance migration (#54814)
 
 Miscellaneous
 """""""""""""
diff --git a/airflow-core/docs/img/airflow_erd.sha256 
b/airflow-core/docs/img/airflow_erd.sha256
index 9ede5601f58..5294f93cecc 100644
--- a/airflow-core/docs/img/airflow_erd.sha256
+++ b/airflow-core/docs/img/airflow_erd.sha256
@@ -1 +1 @@
-9650b3ecb443b35b5626dede72e6235683f616f16c8c8f5ab113fa08d1a27ff7
\ No newline at end of file
+089af505c88848c8c8245f89d5e76fe11c2f4ea7ed4f897e7d0b58e1b4aa5343
\ No newline at end of file
diff --git 
a/airflow-core/src/airflow/migrations/versions/0042_3_0_0_add_uuid_primary_key_to_task_instance_.py
 
b/airflow-core/src/airflow/migrations/versions/0042_3_0_0_add_uuid_primary_key_to_task_instance_.py
index df7965d38e9..c01d5e4463f 100644
--- 
a/airflow-core/src/airflow/migrations/versions/0042_3_0_0_add_uuid_primary_key_to_task_instance_.py
+++ 
b/airflow-core/src/airflow/migrations/versions/0042_3_0_0_add_uuid_primary_key_to_task_instance_.py
@@ -114,28 +114,27 @@ DETERMINISTIC
 BEGIN
     DECLARE unix_time_ms BIGINT;
     DECLARE time_hex CHAR(12);
-    DECLARE rand_hex CHAR(24);
-    DECLARE uuid CHAR(36);
+    DECLARE rand_hex CHAR(20);   -- 10 bytes => 20 hex chars
 
-    -- Convert the passed timestamp to milliseconds since epoch
-    SET unix_time_ms = UNIX_TIMESTAMP(p_timestamp) * 1000;
+    -- milliseconds since epoch (truncation is fine for ms precision)
+    SET unix_time_ms = FLOOR(UNIX_TIMESTAMP(p_timestamp) * 1000);
     SET time_hex = LPAD(HEX(unix_time_ms), 12, '0');
-    SET rand_hex = CONCAT(
-        LPAD(HEX(FLOOR(RAND() * POW(2,32))), 8, '0'),
-        LPAD(HEX(FLOOR(RAND() * POW(2,32))), 8, '0')
-    );
-    SET rand_hex = CONCAT(SUBSTRING(rand_hex, 1, 4), '7', SUBSTRING(rand_hex, 
6));
-    SET rand_hex = CONCAT(SUBSTRING(rand_hex, 1, 12), '8', SUBSTRING(rand_hex, 
14));
-
-    SET uuid = LOWER(CONCAT(
+
+    -- 10 random bytes (CSPRNG), 20 hex chars
+    SET rand_hex = HEX(RANDOM_BYTES(10));
+
+    -- set version nibble to 7 (first of next 4 hex)
+    SET rand_hex = CONCAT('7', SUBSTRING(rand_hex, 2));
+    -- set variant (first hex of next 4) to 8..b; using '8' keeps the top bits 
10
+    SET rand_hex = CONCAT(SUBSTRING(rand_hex, 1, 4), '8', SUBSTRING(rand_hex, 
6));
+
+    RETURN LOWER(CONCAT(
         SUBSTRING(time_hex, 1, 8), '-',
         SUBSTRING(time_hex, 9, 4), '-',
         SUBSTRING(rand_hex, 1, 4), '-',
         SUBSTRING(rand_hex, 5, 4), '-',
-        SUBSTRING(rand_hex, 9)
+        SUBSTRING(rand_hex, 9, 12)
     ));
-
-    RETURN uuid;
 END;
 """
 
diff --git a/reproducible_build.yaml b/reproducible_build.yaml
index bf2493812af..ea55e1f5d95 100644
--- a/reproducible_build.yaml
+++ b/reproducible_build.yaml
@@ -1,2 +1,2 @@
-release-notes-hash: fc6c53b7b5ed75150f32b3e557a26e19
-source-date-epoch: 1755862322
+release-notes-hash: 2266e91b1ec715cbd875be7e086c4949
+source-date-epoch: 1755863207

Reply via email to