Skip to content

[v3-3-test] Fix db migrate failure to Airflow 2.9.2 under PyMySQL driver (#70235) - #72613

Merged
vatsrahul1001 merged 2 commits into
v3-3-testfrom
backport-08e428c-v3-3-test
Sep 8, 2026
Merged

vatsrahul1001 merged 2 commits into
v3-3-testfrom
backport-08e428c-v3-3-test

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor
  • Fix db migrate failure to Airflow 2.9.2 under PyMySQL driver

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: #43690

  • Add newsfragment for MySQL PyMySQL migration fix

  • Fix offline migration for 2.9.2 ORM-consistency revision

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.

  • Address review feedback on MySQL PyMySQL migration fix

Bind the table name as a query parameter in the information_schema
lookup instead of interpolating it into the SQL string, since it's a
value comparison rather than an identifier — matches Airflow's usual
parameter-binding convention even though every call site currently
passes a hardcoded literal. Also correct the docstring: PyMySQL can run
a bare PREPARE statement fine, what it actually can't do is send more
than one statement per cursor.execute() call, because it never enables
CLIENT.MULTI_STATEMENTS.

  • Fixed the PR comments
    (cherry picked from commit 08e428c)

Co-authored-by: Aaryan Mahajan aaryanmhjn@gmail.com

…ver (#70235)

* Fix db migrate failure to Airflow 2.9.2 under PyMySQL driver

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: #43690

* Add newsfragment for MySQL PyMySQL migration fix

* Fix offline migration for 2.9.2 ORM-consistency revision

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.

* Address review feedback on MySQL PyMySQL migration fix

Bind the table name as a query parameter in the information_schema
lookup instead of interpolating it into the SQL string, since it's a
value comparison rather than an identifier — matches Airflow's usual
parameter-binding convention even though every call site currently
passes a hardcoded literal. Also correct the docstring: PyMySQL can run
a bare PREPARE statement fine, what it actually can't do is send more
than one statement per cursor.execute() call, because it never enables
CLIENT.MULTI_STATEMENTS.

* Fixed the PR comments
(cherry picked from commit 08e428c)

Co-authored-by: Aaryan Mahajan <aaryanmhjn@gmail.com>
@boring-cyborg boring-cyborg Bot added the area:db-migrations PRs with DB migration label Sep 7, 2026
@vatsrahul1001
vatsrahul1001 marked this pull request as ready for review September 8, 2026 06:12
@vatsrahul1001 vatsrahul1001 added this to the Airflow 3.3.2 milestone Sep 8, 2026
@vatsrahul1001 vatsrahul1001 added the type:bug-fix Changelog: Bug Fixes label Sep 8, 2026
@vatsrahul1001
vatsrahul1001 merged commit 8acabc3 into v3-3-test Sep 8, 2026
75 checks passed
@vatsrahul1001
vatsrahul1001 deleted the backport-08e428c-v3-3-test branch September 8, 2026 08:11
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 type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants