0

For example:

from sqlmodel import Field, SQLModel, select


class TableX(SQLModel, table=True):
    id: int | None = Field(default=None, primary_key=True)
    x: str


class TableY(SQLModel, table=True):
    id: int
    y: str
    z: str


query = (
    select(TableX)
    .join(TableY, TableX.id == TableY.id)
    .where(TableY.z.in_(["A", "B", "C"]))
)

We get two type errors just in this simple code:

  • TableX.id == TableY.id is annotated as type bool, which is an invalid type for onclause in join().
  • TableY.z is annotated as type str, which has no attribute in_.

The whole project I'm working on, I have to either disable my type-checker or add type: ignore to practically every line of sqlmodel code. Are we using it wrong, or is it just not usable with type checking?

0

0

Browse other questions tagged or ask your own question.