MCPcopy Index your code
hub / github.com/fastapi/sqlmodel / test_model_with_future_annotations

Function test_model_with_future_annotations

tests/test_future_annotations.py:8–33  ·  view source on GitHub ↗
(clear_sqlmodel)

Source from the content-addressed store, hash-verified

6
7
8def test_model_with_future_annotations(clear_sqlmodel):
9 class Hero(SQLModel, table=True):
10 id: Annotated[int | None, Field(primary_key=True)] = None
11 name: str
12 secret_name: str
13 age: int | None = None
14
15 hero = Hero(name="Deadpond", secret_name="Dive Wilson", age=25)
16
17 engine = create_engine("sqlite://")
18 SQLModel.metadata.create_all(engine)
19
20 with Session(engine) as session:
21 session.add(hero)
22 session.commit()
23 session.refresh(hero)
24
25 assert hero.id is not None
26 assert hero.name == "Deadpond"
27 assert hero.secret_name == "Dive Wilson"
28 assert hero.age == 25
29
30 with Session(engine) as session:
31 heroes = session.exec(select(Hero)).all()
32 assert len(heroes) == 1
33 assert heroes[0].name == "Deadpond"
34
35
36def test_model_with_string_annotations(clear_sqlmodel):

Callers

nothing calls this directly

Calls 4

SessionClass · 0.90
selectFunction · 0.90
HeroClass · 0.70
execMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…