Typechecking on id field when querying #624
Answered by YuriiMotov
travis-cook-sfdc asked this question in Questions
-
First Check
Commit to Help
Example Codefrom sqlmodel import Field, Session, SQLModel, create_engine, select class Hero(SQLModel, table=True): id: int | None = Field(default=None, primary_key=True) name: str hero_1 = Hero(name="Foo") engine = create_engine("sqlite://database.db") SQLModel.metadata.create_all(engine) with Session(engine) as session: session.add(hero_1) session.commit() with Session(engine) as session: hero = session.exec(select(Hero)).one() x = dict[int, Hero] = {hero.id: hero}Description
Is there anyway for sqlmodel / mypy to resolve the fact that Operating SystemmacOS Operating System DetailsNo response SQLModel Version0.0.8 Python Version3.11 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Answered by YuriiMotov Aug 19, 2025
Replies: 1 comment
-
| You can add I don't think there are other methods. Only checking the value in runtime |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can add
assert hero.id is not Nonebefore that line.I don't think there are other methods. Only checking the value in runtime