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

SQLModel classes fail type checking with FastCRUD #58

Open
slaarti opened this issue Apr 23, 2024 · 1 comment
Open

SQLModel classes fail type checking with FastCRUD #58

slaarti opened this issue Apr 23, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@slaarti
Copy link
Contributor

slaarti commented Apr 23, 2024

Describe the bug or question

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)
@igorbenav
Copy link
Owner

Thanks, @slaarti, I'm fixing this one ASAP!

@igorbenav igorbenav self-assigned this Apr 23, 2024
@igorbenav igorbenav added the bug Something isn't working label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants