def test_drop_exclude_constraint(self):
autogen_context = self.autogen_context
m = MetaData()
t = Table(
"TTable", m, Column("XColumn", String), Column("YColumn", String)
)
op_obj = ops.DropConstraintOp.from_constraint(
ExcludeConstraint(
(t.c.XColumn, ">"),
where=t.c.XColumn != 2,
using="gist",
name="t_excl_x",
)
)
eq_ignore_whitespace(
autogenerate.render_op_text(autogen_context, op_obj),
"op.drop_constraint('t_excl_x', 'TTable', type_='exclude')",
)
[gw1] linux -- Python 3.11.3 /home/d3/dev/alembic/alembic/.tox/py-sqlalchemy/bin/python
Traceback (most recent call last):
File "/home/d3/dev/alembic/alembic/.tox/py-sqlalchemy/lib/python3.11/site-packages/_pytest/runner.py", line 341, in from_call
result: Optional[TResult] = func()
^^^^^^
File "/home/d3/dev/alembic/alembic/.tox/py-sqlalchemy/lib/python3.11/site-packages/_pytest/runner.py", line 262, in <lambda>
lambda: ihook(item=item, **kwds), when=when, reraise=reraise
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/d3/dev/alembic/alembic/.tox/py-sqlalchemy/lib/python3.11/site-packages/pluggy/_hooks.py", line 433, in __call__
return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/d3/dev/alembic/alembic/.tox/py-sqlalchemy/lib/python3.11/site-packages/pluggy/_manager.py", line 112, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/d3/dev/alembic/alembic/.tox/py-sqlalchemy/lib/python3.11/site-packages/pluggy/_callers.py", line 155, in _multicall
return outcome.get_result()
^^^^^^^^^^^^^^^^^^^^
File "/home/d3/dev/alembic/alembic/.tox/py-sqlalchemy/lib/python3.11/site-packages/pluggy/_result.py", line 108, in get_result
raise exc.with_traceback(exc.__traceback__)
File "/home/d3/dev/alembic/alembic/.tox/py-sqlalchemy/lib/python3.11/site-packages/pluggy/_callers.py", line 80, in _multicall
res = hook_impl.function(*args)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/d3/dev/alembic/alembic/.tox/py-sqlalchemy/lib/python3.11/site-packages/_pytest/runner.py", line 177, in pytest_runtest_call
raise e
File "/home/d3/dev/alembic/alembic/.tox/py-sqlalchemy/lib/python3.11/site-packages/_pytest/runner.py", line 169, in pytest_runtest_call
item.runtest()
File "/home/d3/dev/alembic/alembic/.tox/py-sqlalchemy/lib/python3.11/site-packages/_pytest/python.py", line 1788, in runtest
self.ihook.pytest_pyfunc_call(pyfuncitem=self)
File "/home/d3/dev/alembic/alembic/.tox/py-sqlalchemy/lib/python3.11/site-packages/pluggy/_hooks.py", line 433, in __call__
return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/d3/dev/alembic/alembic/.tox/py-sqlalchemy/lib/python3.11/site-packages/pluggy/_manager.py", line 112, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/d3/dev/alembic/alembic/.tox/py-sqlalchemy/lib/python3.11/site-packages/pluggy/_callers.py", line 116, in _multicall
raise exception.with_traceback(exception.__traceback__)
File "/home/d3/dev/alembic/alembic/.tox/py-sqlalchemy/lib/python3.11/site-packages/pluggy/_callers.py", line 80, in _multicall
res = hook_impl.function(*args)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/d3/dev/alembic/alembic/.tox/py-sqlalchemy/lib/python3.11/site-packages/_pytest/python.py", line 194, in pytest_pyfunc_call
result = testfunction(**testargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/d3/dev/alembic/alembic/tests/test_postgresql.py", line 1272, in test_drop_exclude_constraint
op_obj = ops.DropConstraintOp.from_constraint(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/d3/dev/alembic/alembic/alembic/operations/ops.py", line 175, in from_constraint
type_=types[constraint.__visit_name__],
~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'exclude_constraint'
Describe the bug
Passing an
ExcludeConstraintobject toDropConstraintOp.from_constraintgivesKeyError: 'exclude_constraint'.Expected behavior
A new
DropConstraintobject should be returned, as it the case when passing other constraint types.To Reproduce
Can be reproduced by adding the below unit test:
Error
Versions.