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

create_check_constraint condition argument type doesn't allow boolean expression #1266

Closed
ods opened this issue Jul 3, 2023 · 2 comments
Closed
Labels
bug Something isn't working pep 484 typing related issues PRs (with tests!) welcome

Comments

@ods
Copy link

ods commented Jul 3, 2023

Describe the bug

create_check_constraint's condition argument is declared as condition: Union[str, BinaryExpression], which doesn't accept neither or_(…)/and_(…)

error: Argument 3 to "create_check_constraint" has incompatible type "ColumnElement[bool]"; expected "str | BinaryExpression[Any] | TextClause"  [arg-type]

nor col_expr1 | col_expr2/col_expr1 & col_expr2:

error: Argument 3 to "create_check_constraint" has incompatible type "BooleanClauseList"; expected "str | BinaryExpression[Any] | TextClause"  [arg-type]

Expected behavior

Both described cases work runtime, so type annotation is expected to allow them.

To Reproduce

from alembic import op
import sqlalchemy as sa


def upgrade() -> None:

    op.create_check_constraint(
        "check_constraint",
        "table_name",
        sa.or_(sa.column("a") != 0, sa.column("b") != 0),
    )

Error

error: Argument 3 to "create_check_constraint" has incompatible type "ColumnElement[bool]"; expected "str | BinaryExpression[Any] | TextClause"  [arg-type]

Versions.

  • OS:
  • Python:
  • Alembic: 1.11.1
  • SQLAlchemy: 2.0.17
  • Database:
  • DBAPI:

Additional context

Have a nice day!

@ods ods added the requires triage New issue that requires categorization label Jul 3, 2023
@zzzeek
Copy link
Member

zzzeek commented Jul 3, 2023

if it says "BinaryExpression" that's straight up wrong and seems like an automated tool generated that

@zzzeek zzzeek added bug Something isn't working pep 484 typing related issues and removed requires triage New issue that requires categorization labels Jul 3, 2023
@sqla-tester
Copy link
Collaborator

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

Improve typings https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/4836

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pep 484 typing related issues PRs (with tests!) welcome
Projects
None yet
Development

No branches or pull requests

4 participants