diff --git a/backend/Dockerfile b/backend/Dockerfile index 42ea8d3..5092599 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,4 +1,4 @@ -# Pull official latest Python Docker image (Pulished with version 3.11.0) +# Pull official latest Python Docker image (Published with version 3.11.0) FROM --platform=linux/amd64 python:latest # Set the working directory diff --git a/backend/README.md b/backend/README.md index 8bb8e19..daeafaf 100644 --- a/backend/README.md +++ b/backend/README.md @@ -120,7 +120,7 @@ Check the `pyproject.toml` as the main configuration file for the following pack * Isort * MyPy * PyTest -* Converage +* Coverage --- diff --git a/backend/src/api/dependencies/session.py b/backend/src/api/dependencies/session.py index cb52e34..a2fa985 100644 --- a/backend/src/api/dependencies/session.py +++ b/backend/src/api/dependencies/session.py @@ -12,10 +12,5 @@ async def get_async_session() -> typing.AsyncGenerator[SQLAlchemyAsyncSession, None]: - try: - yield async_db.async_session - except Exception as e: - print(e) - await async_db.async_session.rollback() - finally: - await async_db.async_session.close() + async with async_db.async_session() as session: + yield session diff --git a/backend/src/repository/database.py b/backend/src/repository/database.py index 4fcaaee..c46f354 100644 --- a/backend/src/repository/database.py +++ b/backend/src/repository/database.py @@ -1,6 +1,6 @@ import pydantic from sqlalchemy.ext.asyncio import ( - async_sessionmaker as sqlalchemy_async_sessionmaker, + async_sessionmaker as SQLAlchemyAsyncSessionMaker, AsyncEngine as SQLAlchemyAsyncEngine, AsyncSession as SQLAlchemyAsyncSession, create_async_engine as create_sqlalchemy_async_engine, @@ -23,7 +23,9 @@ def __init__(self): max_overflow=settings.DB_POOL_OVERFLOW, poolclass=SQLAlchemyQueuePool, ) - self.async_session: SQLAlchemyAsyncSession = SQLAlchemyAsyncSession(bind=self.async_engine) + self.async_session: SQLAlchemyAsyncSessionMaker = SQLAlchemyAsyncSessionMaker( + bind=self.async_engine, expire_on_commit=False, class_=SQLAlchemyAsyncSession + ) self.pool: SQLAlchemyPool = self.async_engine.pool @property