From 5c79fbd322904059887cc7e7bdcec49e1e5cf5fe Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 Oct 2025 20:40:17 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20format?= =?UTF-8?q?=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs_src/sql_databases/tutorial002.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs_src/sql_databases/tutorial002.py b/docs_src/sql_databases/tutorial002.py index 71eac10b6..a3d7d4e74 100644 --- a/docs_src/sql_databases/tutorial002.py +++ b/docs_src/sql_databases/tutorial002.py @@ -1,5 +1,5 @@ -from typing import List, Union from contextlib import asynccontextmanager +from typing import List, Union from fastapi import Depends, FastAPI, HTTPException, Query from sqlmodel import Field, Session, SQLModel, create_engine, select @@ -44,14 +44,17 @@ def get_session(): with Session(engine) as session: yield session + @asynccontextmanager async def lifespan(app: FastAPI): models.create_db_and_tables() yield # Can add events for after startup completion here + app = FastAPI(lifespan=lifespan) + @app.post("/heroes/", response_model=HeroPublic) def create_hero(hero: HeroCreate, session: Session = Depends(get_session)): db_hero = Hero.model_validate(hero)