The FastCRUD class expects that the model that's passed to it is a subclass of SQLAlchemy's DeclarativeBase. SQLModel, meanwhile, derives a metaclass from SQLAlchemy's DeclarativeMeta and uses that as its base. It therefore isn't a subclass of DeclarativeBase and passing a class derived from SQLModel to FastCRUD fails type checking:
$ pyright mve.py
.../mve.py
.../mve.py:12:22 - error: Argument of type "type[Store]" cannot be assigned to parameter "model" of type "type[ModelType@FastCRUD]" in function "__init__"
Type "Store" is incompatible with type "DeclarativeBase"
"Store" is incompatible with "DeclarativeBase" (reportArgumentType)
1 error, 0 warnings, 0 informations
To Reproduce
The MVE used to produce the above error message. The documentation says this should work, and it probably does actually run, but again, it fails type checking (using "standard" typeCheckingMode):
from typing import Annotated
from fastcrud import FastCRUD
from sqlmodel import Field, SQLModel
class Store(SQLModel, table=True):
id: Annotated[str, Field(primary_key=True)]
name: Annotated[str, Field(unique=True)]
StoreCRUD = FastCRUD(Store)
Describe the bug or question
The
FastCRUD
class expects that the model that's passed to it is a subclass of SQLAlchemy'sDeclarativeBase
. SQLModel, meanwhile, derives a metaclass from SQLAlchemy'sDeclarativeMeta
and uses that as its base. It therefore isn't a subclass ofDeclarativeBase
and passing a class derived fromSQLModel
toFastCRUD
fails type checking:To Reproduce
The MVE used to produce the above error message. The documentation says this should work, and it probably does actually run, but again, it fails type checking (using "standard"
typeCheckingMode
):