diff --git a/backend/app/api/deps.py b/backend/app/api/deps.py index b19e72b9..bf9fb57c 100644 --- a/backend/app/api/deps.py +++ b/backend/app/api/deps.py @@ -1,13 +1,12 @@ from typing import AsyncIterator from app.core import auth -from app.db.session import SessionLocal, engine +from app.db.session import SessionLocal current_active_user = auth.fastapi_users.current_user(active=True) current_active_superuser = auth.fastapi_users.current_user(active=True, superuser=True) async def get_db() -> AsyncIterator[SessionLocal]: # type: ignore[valid-type] - db = SessionLocal() - yield db - await db.close() + async with SessionLocal() as db: + yield db diff --git a/backend/app/main.py b/backend/app/main.py index f0347440..73a1f414 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -15,6 +15,7 @@ from app.api.internal.endpoints.remote import httpx_client_wrapper from app.core.config import settings from app.db.init_db import create_superuser +from app.db.session import engine if settings.DEBUG: logging.basicConfig(level=logging.DEBUG) @@ -40,6 +41,7 @@ async def lifespan(app: FastAPI): httpx_client_wrapper.start() yield await httpx_client_wrapper.stop() + await engine.dispose() app = FastAPI(