Skip to content

Commit

Permalink
fix: more robust handling of async sessions (#360) (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe authored Jan 3, 2024
1 parent 970b400 commit 86510e8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 3 additions & 4 deletions backend/app/api/deps.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -40,6 +41,7 @@ async def lifespan(app: FastAPI):
httpx_client_wrapper.start()
yield
await httpx_client_wrapper.stop()
await engine.dispose()


app = FastAPI(
Expand Down

0 comments on commit 86510e8

Please sign in to comment.