Where the Session Comes From
From src/planner/core/db.py, which every team uses:
def get_session() -> Generator[Session, None, None]:
"""Yield one session per request, and close it when the request ends."""
with Session(engine) as session:
yield session
SessionDep = Annotated[Session, Depends(get_session)]
Depends(get_session) tells FastAPI: call get_session for me; pass in what it yields
- One session per request; it closes even if your function raises an exception
- No endpoint ever creates its own engine or session
- The engine reads
DATABASE_URL, so the same code runs on SQLite and PostgreSQL