Skip to content

Commit f63215b

Browse files
committed
fix: convert all FastAPI lifespan context managers to async and resolve MRO issue
- Change SoftDeleteMixin to not inherit from SQLModel (avoids MRO conflict) - Update all FastAPI tutorial files to use @asynccontextmanager instead of @contextmanager for lifespan (FastAPI 0.111+ requirement) - Add missing imports (HTTPException, Depends, Query) where needed - Fix test that called deprecated on_startup() method
1 parent c43b622 commit f63215b

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

docs_src/tutorial/fastapi/update/tutorial002_py310.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,13 @@ def hash_password(password: str) -> str:
4545
return f"not really hashed {password} hehehe"
4646

4747

48-
def get_session():
49-
with Session(engine) as session:
50-
yield session
51-
52-
53-
app = FastAPI()
48+
@asynccontextmanager
49+
async def lifespan(app: FastAPI):
50+
create_db_and_tables()
51+
yield
5452

5553

56-
@app.on_event("startup")
57-
def on_startup():
58-
create_db_and_tables()
54+
app = FastAPI(lifespan=lifespan)
5955

6056

6157
@app.post("/heroes/", response_model=HeroPublic)

0 commit comments

Comments
 (0)