Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Fix MySQL downgrade from 3.3.0 on deadline_alert.interval JSON conversion#68337

Open
vatsrahul1001 wants to merge 1 commit into
mainfrom
fix-mysql-downgrade-deadline-interval-json
Open

Fix MySQL downgrade from 3.3.0 on deadline_alert.interval JSON conversion#68337
vatsrahul1001 wants to merge 1 commit into
mainfrom
fix-mysql-downgrade-deadline-interval-json

Conversation

@vatsrahul1001

@vatsrahul1001 vatsrahul1001 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Migration 0117 (8812eb67b63c) converts deadline_alert.interval from FLOAT to JSON on upgrade and back on downgrade. On MySQL the downgrade unwrapped the value with CAST(... AS DOUBLE) inside an UPDATE that runs while the column is still typed JSON. Writing a non-JSON DOUBLE into a JSON column makes MySQL reject the whole statement:

(MySQLdb.OperationalError) (3140, 'Invalid JSON text: "not a JSON text, may need CAST" at position 0 in value for column 'deadline_alert.interval'.')

So airflow db downgrade fails on MySQL for any deployment with at least one deadline_alert row.

The fix keeps the unwrapped value as a JSON number in the UPDATE and lets the subsequent column retype to FLOAT perform the cast — mirroring how the PostgreSQL branch defers the cast to its ALTER ... USING clause. The offline-mode MySQL instructions had the same defect and are corrected too.

Verified on MySQL 8.0: the original SQL reproduces error 3140; the fixed UPDATE succeeds and the subsequent MODIFY ... FLOAT converts the JSON numbers to 300/60.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 4.8)

Generated-by: Claude Code (Opus 4.8) following the guidelines

@boring-cyborg boring-cyborg Bot added area:db-migrations PRs with DB migration area:deadline-alerts AIP-86 (former AIP-57) labels Jun 10, 2026
@vatsrahul1001 vatsrahul1001 requested a review from vincbeck June 10, 2026 12:57
@vatsrahul1001

Copy link
Copy Markdown
Contributor Author

@SameerMesiah97

@vatsrahul1001 vatsrahul1001 added this to the Airflow 3.3.0 milestone Jun 10, 2026
@vatsrahul1001 vatsrahul1001 added the kind:bug This is a clearly a bug label Jun 10, 2026
@vatsrahul1001 vatsrahul1001 force-pushed the fix-mysql-downgrade-deadline-interval-json branch from 3f9e467 to 8aec6f8 Compare June 10, 2026 13:00
@ephraimbuddy ephraimbuddy requested a review from Copilot June 10, 2026 13:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a MySQL-specific failure in migration 0117’s downgrade path by ensuring the downgrade UPDATE writes valid JSON values while the column is still typed JSON, deferring numeric casting until the subsequent column retype.

Changes:

  • Refactors the MySQL downgrade value-conversion SQL into a helper (_mysql_downgrade_interval_value_sql) that keeps unwrapped values as JSON numbers.
  • Updates the offline/manual MySQL downgrade instructions to avoid casting JSON-extracted values to non-JSON types during the UPDATE.
  • Adds a MySQL regression test that reproduces the failure mode and verifies successful downgrade conversion back to FLOAT.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
airflow-core/src/airflow/migrations/versions/0117_3_3_0_change_deadline_interval_to_json.py Fixes MySQL downgrade SQL to avoid invalid JSON writes; updates offline instructions; factors SQL into a helper.
airflow-core/tests/unit/migrations/test_0117_deadline_interval_json_migration.py Adds a regression test ensuring the MySQL downgrade conversion succeeds and round-trips to FLOAT.

…sion

The 3.3.0 migration 0117 (8812eb67b63c) converts deadline_alert.interval
to JSON on upgrade and back to FLOAT on downgrade. On MySQL the downgrade
unwrapped the value with CAST(... AS DOUBLE) inside an UPDATE that runs
while the column is still typed JSON. Writing a non-JSON DOUBLE into a JSON
column makes MySQL reject the whole statement with ER_INVALID_JSON_TEXT
(3140), so `airflow db downgrade` fails for any deployment that has at
least one deadline_alert row.

Keep the unwrapped value as a JSON number in the UPDATE and let the
subsequent column retype to FLOAT perform the cast, mirroring how the
PostgreSQL branch defers the cast to its ALTER ... USING clause. The
offline-mode MySQL instructions had the same defect and are corrected too.

Adds a MySQL-backend regression test that seeds rows and runs the
migration's conversion SQL; the existing migration stairway missed this
because it runs against an empty schema (zero rows updated never trips
MySQL's per-row JSON validation).
@vatsrahul1001 vatsrahul1001 force-pushed the fix-mysql-downgrade-deadline-interval-json branch from 8aec6f8 to d911e93 Compare June 10, 2026 14:04

@SameerMesiah97 SameerMesiah97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks for fixing it.

@SameerMesiah97

Copy link
Copy Markdown
Contributor

@SameerMesiah97

All good with me if you want this to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:db-migrations PRs with DB migration area:deadline-alerts AIP-86 (former AIP-57) kind:bug This is a clearly a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants