Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to pass ExcludeConstraint to DropConstraintOp.from_constraint #1300

Closed
DJHills opened this issue Aug 23, 2023 · 5 comments
Closed

Unable to pass ExcludeConstraint to DropConstraintOp.from_constraint #1300

DJHills opened this issue Aug 23, 2023 · 5 comments
Labels
bug Something isn't working op directives postgresql
Milestone

Comments

@DJHills
Copy link
Contributor

DJHills commented Aug 23, 2023

Describe the bug
Passing an ExcludeConstraint object to DropConstraintOp.from_constraint gives KeyError: 'exclude_constraint'.

Expected behavior
A new DropConstraint object should be returned, as it the case when passing other constraint types.

To Reproduce
Can be reproduced by adding the below unit test:

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')",
    )

Error

[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'

Versions.

  • OS: Ubuntu 20.04
  • Python: 3.11
  • Alembic: 1.11.3
  • SQLAlchemy: 1.4.48
  • Database: Postgres 10.20
  • DBAPI: psycopg2==2.8.4
@DJHills DJHills added the requires triage New issue that requires categorization label Aug 23, 2023
DJHills added a commit to DJHills/alembic that referenced this issue Aug 23, 2023
DJHills added a commit to DJHills/alembic that referenced this issue Aug 23, 2023
@DJHills
Copy link
Contributor Author

DJHills commented Aug 23, 2023

Fixed by PR #1301

@zzzeek zzzeek added bug Something isn't working op directives and removed requires triage New issue that requires categorization labels Aug 23, 2023
@zzzeek
Copy link
Member

zzzeek commented Aug 23, 2023

please ping me when you update the PR since I dont get an email

@DJHills
Copy link
Contributor Author

DJHills commented Aug 24, 2023

@zzzeek - PR updated.

@sqla-tester
Copy link
Collaborator

d3 has proposed a fix for this issue in the main branch:

Fixes #1300: Inability to pass an ExcludeConstraint object to DropConstraint.from_constraint https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/4832

DJHills added a commit to DJHills/alembic that referenced this issue Aug 29, 2023
@sqla-tester
Copy link
Collaborator

d3 has proposed a fix for this issue in the main branch:

Allow passoing ExcludeConstraint to DropConstraint.from_constraint https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/4832

@CaselIT CaselIT added this to the 1.12 milestone Aug 31, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working op directives postgresql
Projects
None yet
Development

No branches or pull requests

4 participants