Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork14
Open
Description
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
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]"
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.
Configuration
- Python version : 3.13
- FastAPI version : 0.115.8
- FastAPI Users version : 14.0.1