Skip to content

Commit 5a6cc24

Browse files
amoghrajeshkaxil
authored andcommitted
Fix upgrade failure when xcom contains NaN in string values (#57614)
(cherry picked from commit 376ab5d)
1 parent 0725199 commit 5a6cc24

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
db7901e22801d299714b84b9a676081b12bc6247de807cb2469f3c59bdabcfad
1+
977556bd7302c9f753e206b6fa0bfb3a2b123d2cb1b3ef177460b02dd10e10b4

airflow-core/src/airflow/migrations/versions/0049_3_0_0_remove_pickled_data_from_xcom_table.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,12 @@ def upgrade():
114114

115115
# Update the values from nan to nan string
116116
if dialect == "postgresql":
117+
# Replace standalone NaN tokens only (not NaN inside string values)
118+
# Use regex with word boundaries to match only standalone NaN tokens
117119
conn.execute(
118120
text("""
119121
UPDATE xcom
120-
SET value = convert_to(replace(convert_from(value, 'UTF8'), 'NaN', '"nan"'), 'UTF8')
122+
SET value = convert_to(regexp_replace(convert_from(value, 'UTF8'), '\\bNaN\\b', '"nan"'), 'UTF8')
121123
WHERE value IS NOT NULL AND get_byte(value, 0) != 128
122124
""")
123125
)
@@ -133,10 +135,12 @@ def upgrade():
133135
"""
134136
)
135137
elif dialect == "mysql":
138+
# Replace standalone NaN tokens only (not NaN inside string values)
139+
# MySQL 8.0 supports REGEXP_REPLACE with word boundaries, use that here
136140
conn.execute(
137141
text("""
138142
UPDATE xcom
139-
SET value = CONVERT(REPLACE(CONVERT(value USING utf8mb4), 'NaN', '"nan"') USING BINARY)
143+
SET value = CONVERT(REGEXP_REPLACE(CONVERT(value USING utf8mb4), '[[:<:]]NaN[[:>:]]', '"nan"') USING BINARY)
140144
WHERE value IS NOT NULL AND HEX(SUBSTRING(value, 1, 1)) != '80'
141145
""")
142146
)

0 commit comments

Comments
 (0)