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

Function update_hero

docs_src/tutorial/fastapi/update/tutorial001_py310.py:75–85  ·  view source on GitHub ↗
(hero_id: int, hero: HeroUpdate)

Source from the content-addressed store, hash-verified

73
74@app.patch("/heroes/{hero_id}", response_model=HeroPublic)
75def update_hero(hero_id: int, hero: HeroUpdate):
76 with Session(engine) as session:
77 db_hero = session.get(Hero, hero_id)
78 if not db_hero:
79 raise HTTPException(status_code=404, detail="Hero not found")
80 hero_data = hero.model_dump(exclude_unset=True)
81 db_hero.sqlmodel_update(hero_data)
82 session.add(db_hero)
83 session.commit()
84 session.refresh(db_hero)
85 return db_hero

Callers

nothing calls this directly

Calls 3

SessionClass · 0.90
model_dumpMethod · 0.80
sqlmodel_updateMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…