Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Hack on typing returns typing error on sqlalchemywhere clause #19

Open
Labels
bugSomething isn't working
@8area8

Description

@8area8

Describe the bug

Currently the code hacks the handling ofUser attributes with a condition onTYPE_CHECKING. This hack should no longer exist because mypy now handles sqlalchemy field types correctly.

The hack in the source code

https://github.com/fastapi-users/fastapi-users-db-sqlalchemy/blob/main/fastapi_users_db_sqlalchemy/__init__.py#L25

classSQLAlchemyBaseUserTable(Generic[ID]):"""Base SQLAlchemy users table definition."""__tablename__="user"ifTYPE_CHECKING:# pragma: no coverid:IDemail:strhashed_password:stris_active:boolis_superuser:boolis_verified:boolelse:email:Mapped[str]=mapped_column(String(length=320),unique=True,index=True,nullable=False        )hashed_password:Mapped[str]=mapped_column(String(length=1024),nullable=False        )is_active:Mapped[bool]=mapped_column(Boolean,default=True,nullable=False)is_superuser:Mapped[bool]=mapped_column(Boolean,default=False,nullable=False        )is_verified:Mapped[bool]=mapped_column(Boolean,default=False,nullable=False        )

The typing error in the use of the User model.

Cannot assign argument of type "bool" to parameter "whereclause" of type "_ColumnExpressionArgument[bool]" in function "where"Type "bool" is not assignable to type "_ColumnExpressionArgument[bool]""bool" is not assignable to "ColumnElement[bool]""bool" is incompatible with protocol "_HasClauseElement[bool]""__clause_element__" is not present"bool" is not assignable to "SQLCoreOperations[bool]""bool" is not assignable to "ExpressionElementRole[bool]""bool" is not assignable to "TypedColumnsClauseRole[bool]"Type "bool" is not assignable to type "() -> ColumnElement[bool]"

Image

To Reproduce

  • Opens a code editor that supports Python type checking.
  • Write a where clause with the User model.

Expected behavior

Normally Pylance or mypy should not be in error inwhere clauses.

Image

Configuration

  • Python version : 3.13
  • FastAPI version : 0.115.8
  • FastAPI Users version : 14.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp