]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Avoid deprecation warning in add/drop constraint
authorFederico Caselli <cfederico87@gmail.com>
Tue, 16 Dec 2025 20:30:47 +0000 (21:30 +0100)
committerFederico Caselli <cfederico87@gmail.com>
Tue, 16 Dec 2025 20:45:19 +0000 (21:45 +0100)
Ensure that alembic is compatible with the changes added in
https://github.com/sqlalchemy/sqlalchemy/issues/13006
by explicitly setting isolate_from_table=True in sqlalchemy 2.1

Change-Id: I0dd3b2aa2932ca11fbde113fe4d92306fb1f2bbb

alembic/ddl/impl.py
alembic/ddl/sqlite.py
docs/build/unreleased/constraint_deprecation.rst [new file with mode: 0644]

index d352f12ee7dd90ce5121d81908e0f915b03d2e23..4e3f29ae7d29b29d19e56b844f23c2e7a76503b6 100644 (file)
@@ -399,11 +399,15 @@ class DefaultImpl(metaclass=ImplMeta):
             )
         )
 
-    def add_constraint(self, const: Any) -> None:
+    def add_constraint(self, const: Any, **kw: Any) -> None:
         if const._create_rule is None or const._create_rule(self):
-            self._exec(schema.AddConstraint(const))
+            if sqla_compat.sqla_2_1:
+                kw.setdefault("isolate_from_table", True)
+            self._exec(schema.AddConstraint(const, **kw))
 
     def drop_constraint(self, const: Constraint, **kw: Any) -> None:
+        if sqla_compat.sqla_2_1:
+            kw.setdefault("isolate_from_table", True)
         self._exec(schema.DropConstraint(const, **kw))
 
     def rename_table(
index 5f141330fb8bb32d5c2c01996824ccaa2151a39a..c260d53faabefd839d69a4581ebb6dfd3728043e 100644 (file)
@@ -74,7 +74,7 @@ class SQLiteImpl(DefaultImpl):
         else:
             return False
 
-    def add_constraint(self, const: Constraint):
+    def add_constraint(self, const: Constraint, **kw: Any):
         # attempt to distinguish between an
         # auto-gen constraint and an explicit one
         if const._create_rule is None:
diff --git a/docs/build/unreleased/constraint_deprecation.rst b/docs/build/unreleased/constraint_deprecation.rst
new file mode 100644 (file)
index 0000000..c156dcf
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: usecase
+
+    Avoid deprecation warning in add/drop constraint added in SQLAlchemy 2.1.
+    Ensure that alembic is compatible with the changes added in
+    https://github.com/sqlalchemy/sqlalchemy/issues/13006
+    by explicitly setting ``isolate_from_table=True`` when running with
+    SQLAlchemy 2.1 or greater.