From f2b605a02ac5adea32ade9e7a0d726714fddb3b3 Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Mon, 25 Aug 2025 22:59:43 +0200 Subject: [PATCH] adapt alembic for the inherit_schema change sqlalchemy 2.1 This adapts alembic to ignore the inherit_schema argument Change-Id: Ib0f10521fe4e22855612b0cac0d44e2edaec7b3e --- alembic/ddl/mysql.py | 2 +- alembic/util/sqla_compat.py | 7 +++++++ tests/test_autogen_render.py | 5 ++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/alembic/ddl/mysql.py b/alembic/ddl/mysql.py index 8f5f9252..3d7cf21a 100644 --- a/alembic/ddl/mysql.py +++ b/alembic/ddl/mysql.py @@ -507,7 +507,7 @@ def _mysql_drop_constraint( # note that SQLAlchemy as of 1.2 does not yet support # DROP CONSTRAINT for MySQL/MariaDB, so we implement fully # here. - if compiler.dialect.is_mariadb: # type: ignore[attr-defined] + if compiler.dialect.is_mariadb: return "ALTER TABLE %s DROP CONSTRAINT %s" % ( compiler.preparer.format_table(constraint.table), compiler.preparer.format_constraint(constraint), diff --git a/alembic/util/sqla_compat.py b/alembic/util/sqla_compat.py index a909ead7..194e1281 100644 --- a/alembic/util/sqla_compat.py +++ b/alembic/util/sqla_compat.py @@ -70,6 +70,7 @@ _vers = tuple( sqla_14_18 = _vers >= (1, 4, 18) sqla_14_26 = _vers >= (1, 4, 26) sqla_2 = _vers >= (2,) +sqla_2_1 = _vers >= (2, 1) sqlalchemy_version = __version__ if TYPE_CHECKING: @@ -493,3 +494,9 @@ def is_expression(expr: Any) -> bool: if not isinstance(expr, ColumnClause) or expr.is_literal: return True return False + + +def _inherit_schema_deprecated() -> bool: + # at some point in 2.1 inherit_schema was replaced with a property + # so that's preset at the class level, while before it wasn't. + return sqla_2_1 and hasattr(sqltypes.Enum, "inherit_schema") diff --git a/tests/test_autogen_render.py b/tests/test_autogen_render.py index f9b3c28a..c5f5565c 100644 --- a/tests/test_autogen_render.py +++ b/tests/test_autogen_render.py @@ -1763,7 +1763,10 @@ class AutogenRenderTest(TestBase): ) def _check_enum_inherit_schema(self, enum): - if enum.inherit_schema: + if ( + not sqla_compat._inherit_schema_deprecated() + and enum.inherit_schema + ): return enum, ", inherit_schema=True" else: return enum, "" -- 2.47.3