Home / Function/ update_hero() — fastapi Function Reference

update_hero() — fastapi Function Reference

Architecture documentation for the update_hero() function in tutorial002_an_py39.py from the fastapi codebase.

Entity Profile

Dependency Diagram

graph TD
  601f91ed_f5e8_f2b4_3439_86f63793e08b["update_hero()"]
  de4b5dc2_6a42_bcea_3d1b_550a5d21248e["tutorial002_an_py39.py"]
  601f91ed_f5e8_f2b4_3439_86f63793e08b -->|defined in| de4b5dc2_6a42_bcea_3d1b_550a5d21248e
  style 601f91ed_f5e8_f2b4_3439_86f63793e08b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

docs_src/sql_databases/tutorial002_an_py39.py lines 84–93

def update_hero(hero_id: int, hero: HeroUpdate, session: SessionDep):
    hero_db = session.get(Hero, hero_id)
    if not hero_db:
        raise HTTPException(status_code=404, detail="Hero not found")
    hero_data = hero.model_dump(exclude_unset=True)
    hero_db.sqlmodel_update(hero_data)
    session.add(hero_db)
    session.commit()
    session.refresh(hero_db)
    return hero_db

Domain

Subdomains

Frequently Asked Questions

What does update_hero() do?
update_hero() is a function in the fastapi codebase, defined in docs_src/sql_databases/tutorial002_an_py39.py.
Where is update_hero() defined?
update_hero() is defined in docs_src/sql_databases/tutorial002_an_py39.py at line 84.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free