Skip to content

is it possible to support filter_by check in sqlalchemy #1072

Closed

Description

@asukaminato0721

background:

In SQLAlchemy, two styles:

1

select(Table).where(Table.col == other)

2

select(Table).filter_by(col = other)

But in 2, col is Any, so no check here.

Activity

  1. rchen152 commented on Sep 12, 2025

    @rchen152
    Contributor

    @asukaminato0721 Thank you for the report! Could you provide a bit more detail to help me understand the issue? What are select and Table? (Are the defined somewhere in your code? Imported from SQLAlchemy?)

  2. added
    questionFurther information is requested
    sqlalchemyIssues related to support for SQLAlchemy 2.0
    and removed on Sep 12, 2025
  3. asukaminato0721 commented on Sep 12, 2025

    @asukaminato0721
    CollaboratorAuthor

    a minimal example:

    from sqlalchemy.orm import DeclarativeBase
    from sqlalchemy.orm import Mapped
    from sqlalchemy.orm import mapped_column
    from sqlalchemy import select
    
    
    class Base(DeclarativeBase):
        pass
    
    
    class Table(Base):
        __tablename__ = "user_account"
    
        col: Mapped[str]

    select ref: https://docs.sqlalchemy.org/en/20/core/selectable.html#sqlalchemy.sql.expression.select

    filter_by: https://docs.sqlalchemy.org/en/20/core/selectable.html#sqlalchemy.sql.expression.Select.filter_by

    current problem is

    sqlalchemy.sql.expression.Select.filter_by(**kwargs: Any) → Self

    as the signature shows, Any, so no check here.

  4. added theissue type on Sep 12, 2025
  5. rchen152 commented on Sep 12, 2025

    @rchen152
    Contributor

    Thanks, that's really helpful! If the function is annotated with **kwargs: Any in the source, getting more precise types would most likely require hard-coded logic in Pyrefly for SQLAlchemy. That's definitely something we can look into (we've already done something similar for Pydantic), but timeline-wise, it'll likely come after #920 and fixing any obvious bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

has-open-prsqlalchemyIssues related to support for SQLAlchemy 2.0

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions