Fix db migrate failure to Airflow 2.9.2 under PyMySQL driver - #70235
Open
Aaryan123456679 wants to merge 3 commits into
Open
Fix db migrate failure to Airflow 2.9.2 under PyMySQL driver#70235Aaryan123456679 wants to merge 3 commits into
Aaryan123456679 wants to merge 3 commits into
Conversation
Contributor
Author
|
Added a newsfragment for the release notes. |
Upgrading through revision 686269002441 raised pymysql.err.ProgrammingError because the migration used MySQL's PREPARE/EXECUTE/DEALLOCATE PREPARE dynamic SQL to conditionally drop unique constraints, which PyMySQL's driver does not support (see PyMySQL/PyMySQL#202). Replaced with a plain lookup of existing constraints from information_schema.TABLE_CONSTRAINTS followed by conditional ALTER TABLE ... DROP INDEX statements, which works with any MySQL driver. Verified against a real MySQL/PyMySQL backend: downgrading to bff083ad727d and re-running db migrate now completes without error. closes: apache#43690
The PyMySQL online-mode fix in this migration queries information_schema.TABLE_CONSTRAINTS via conn.execute() to decide which legacy unique constraints to drop. In Alembic's offline (--sql) mode there is no live connection, so conn.execute() returns None and iterating over it raises TypeError, breaking the CI "Test offline migration" step. Guard the query-then-conditionally-drop logic behind context.is_offline_mode(), falling back to the original dynamic prepare/execute/deallocate SQL text for the offline branch, since that text is only ever emitted as script output there rather than executed directly.
Aaryan123456679
force-pushed
the
fix/mysql-pymysql-migration-43690
branch
from
July 22, 2026 18:47
977c6d0 to
3caee08
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migrating the metadata database to Airflow 2.9.2 (revision
686269002441) raisedpymysql.err.ProgrammingErroron MySQL when using the PyMySQL driver, because the migration used MySQL'sPREPARE/EXECUTE/DEALLOCATE PREPAREdynamic SQL to conditionally drop unique constraints on theconnectionanddag_runtables. This syntax is not supported by PyMySQL (see PyMySQL#202), so any deployment using PyMySQL as its MySQL driver could not migrate past this revision.Replaced the dynamic SQL with a plain lookup of existing constraints from
information_schema.TABLE_CONSTRAINTS, followed by conditionalALTER TABLE ... DROP INDEXstatements — this works with any MySQL driver.Verified against a real MySQL backend forced to use
mysql+pymysql://: downgrading tobff083ad727dand re-runningairflow db migratenow completes without error, and the expected unique constraints (connection_conn_id_uq,dag_run_dag_id_*_key) are present afterward.closes: #43690
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Sonnet 5) following the guidelines