]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
handle DropConstraint.if_exists version requirements 1651/head
authorAaron Griffin <aaron@growtherapy.com>
Thu, 24 Apr 2025 22:30:54 +0000 (17:30 -0500)
committerAaron Griffin <aaron@growtherapy.com>
Thu, 24 Apr 2025 22:30:54 +0000 (17:30 -0500)
alembic/operations/toimpl.py
tests/test_op.py

index c8190965adf09f3dd5dc58c291f4e8d7a4c58226..96704d588576a777900fe971aa949ef634bca4f3 100644 (file)
@@ -7,7 +7,7 @@ from sqlalchemy import schema as sa_schema
 
 from . import ops
 from .base import Operations
-from ..util.sqla_compat import _copy
+from ..util.sqla_compat import _copy, sqla_2
 
 if TYPE_CHECKING:
     from sqlalchemy.sql.schema import Table
@@ -199,6 +199,8 @@ def drop_constraint(
 ) -> None:
     kw = {}
     if operation.if_exists is not None:
+        if not sqla_2:
+            raise NotImplementedError("SQLAlchemy 2.0 required")
         kw["if_exists"] = operation.if_exists
     operations.impl.drop_constraint(
         operations.schema_obj.generic_constraint(
index 4522e44c5da81d1afc2d0686a658c2ed7740840b..39960318bf268818f3c6df0ac8d127b40858b784 100644 (file)
@@ -823,8 +823,14 @@ class OpTest(TestBase):
 
     def test_drop_constraint_if_exists(self):
         context = op_fixture()
-        op.drop_constraint("foo_bar_bat", "t1", if_exists=True)
-        context.assert_("ALTER TABLE t1 DROP CONSTRAINT IF EXISTS foo_bar_bat")
+        if sqla_compat.sqla_2:
+            op.drop_constraint("foo_bar_bat", "t1", if_exists=True)
+            context.assert_("ALTER TABLE t1 DROP CONSTRAINT IF EXISTS foo_bar_bat")
+        else:
+            with expect_raises_message(
+                NotImplementedError, "SQLAlchemy 2.0 required"
+            ):
+                op.drop_constraint("foo_bar_bat", "t1", if_exists=True)
 
     def test_create_index(self):
         context = op_fixture()