Skip to content

Commit c94816e

Browse files
committed
Avoid deprecation warning in add/drop constraint
Ensure that alembic is compatible with the changes added in sqlalchemy/sqlalchemy#13006 by explicitly setting isolate_from_table=True in sqlalchemy 2.1 Change-Id: I0dd3b2aa2932ca11fbde113fe4d92306fb1f2bbb
1 parent 4fff3d2 commit c94816e

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

alembic/ddl/impl.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,15 @@ def drop_column(
399399
)
400400
)
401401

402-
def add_constraint(self, const: Any) -> None:
402+
def add_constraint(self, const: Any, **kw: Any) -> None:
403403
if const._create_rule is None or const._create_rule(self):
404-
self._exec(schema.AddConstraint(const))
404+
if sqla_compat.sqla_2_1:
405+
kw.setdefault("isolate_from_table", True)
406+
self._exec(schema.AddConstraint(const, **kw))
405407

406408
def drop_constraint(self, const: Constraint, **kw: Any) -> None:
409+
if sqla_compat.sqla_2_1:
410+
kw.setdefault("isolate_from_table", True)
407411
self._exec(schema.DropConstraint(const, **kw))
408412

409413
def rename_table(

alembic/ddl/sqlite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def requires_recreate_in_batch(
7474
else:
7575
return False
7676

77-
def add_constraint(self, const: Constraint):
77+
def add_constraint(self, const: Constraint, **kw: Any):
7878
# attempt to distinguish between an
7979
# auto-gen constraint and an explicit one
8080
if const._create_rule is None:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. change::
2+
:tags: usecase
3+
4+
Avoid deprecation warning in add/drop constraint added in SQLAlchemy 2.1.
5+
Ensure that alembic is compatible with the changes added in
6+
https://github.com/sqlalchemy/sqlalchemy/issues/13006
7+
by explicitly setting ``isolate_from_table=True`` when running with
8+
SQLAlchemy 2.1 or greater.

0 commit comments

Comments
 (0)