]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
adapt alembic for the inherit_schema change sqlalchemy 2.1
authorFederico Caselli <cfederico87@gmail.com>
Mon, 25 Aug 2025 20:59:43 +0000 (22:59 +0200)
committerFederico Caselli <cfederico87@gmail.com>
Tue, 26 Aug 2025 22:19:57 +0000 (00:19 +0200)
This adapts alembic to ignore the inherit_schema argument

Change-Id: Ib0f10521fe4e22855612b0cac0d44e2edaec7b3e

alembic/ddl/mysql.py
alembic/util/sqla_compat.py
tests/test_autogen_render.py

index 8f5f9252663d967bfb29b5764dc63634f3f97a7e..3d7cf21a49a3b724ccf3eb2335c37b90556d70d1 100644 (file)
@@ -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),
index a909ead7f4a5a84728a355685fe417e6c304d5aa..194e1281de58065bc92840f8f0691c4d98a714a1 100644 (file)
@@ -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")
index f9b3c28a7f171747665897c191948e232ca65691..c5f5565ce36fcd62a8aa45174c763ebe02ddd0d6 100644 (file)
@@ -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, ""