Example Code
query = select(User).options(selectinload(User.team)).offset(offset).limit(limit)
Description
Hello,
I’m running a one-to-many, Team to User classic relationship.
Table User declares field team_id which is a FK to Team.id. and relationship team for loading.
class User(SQLModel, table=True)
…
team_id: str | None = Field(
default=None,
foreign_key=”team.id”,
}
team: Team | None = Relationship(back_populates=”users”)
All is good, except a MyPy typing error on selectinload() method:
error: Argument 1 to “selectinload” has incompatible type “Team | None”;
expected “Literal[‘*’] | QueryableAttribute[Any]” [arg-type]
When using:
from sqlalchemy.orm import selectinload
query = select(User).options(selectinload(User.team)).offset(offset).limit(limit)
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.16
SQLAlchemy 2.0.29
Python Version
Python 3.11.7
so i tried to ignore the lines, but i get always the runtime greenlet error with can´t call await_only().
user24810018 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.