From 1d7c8a73c94faf4d61f1f22e478a4e2e3a56c8d2 Mon Sep 17 00:00:00 2001 From: abdelrahman Date: Fri, 27 Mar 2026 00:09:55 +0200 Subject: [PATCH 1/7] Fix async session handling by using AsyncSessionMaker --- backend/src/api/dependencies/session.py | 9 ++------- backend/src/repository/database.py | 4 ++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/backend/src/api/dependencies/session.py b/backend/src/api/dependencies/session.py index cb52e34..f8090f3 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 \ No newline at end of file diff --git a/backend/src/repository/database.py b/backend/src/repository/database.py index 4fcaaee..3abd48b 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,7 @@ 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) self.pool: SQLAlchemyPool = self.async_engine.pool @property From e490b75cf1f24a9077bde9da08838a9e2e5209bb Mon Sep 17 00:00:00 2001 From: abdelrahman Date: Fri, 27 Mar 2026 00:29:48 +0200 Subject: [PATCH 2/7] Add class_=AsyncSession to AsyncSessionMaker to make it explicit that it generates async sessions. --- backend/src/repository/database.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/repository/database.py b/backend/src/repository/database.py index 3abd48b..cd850b6 100644 --- a/backend/src/repository/database.py +++ b/backend/src/repository/database.py @@ -23,7 +23,7 @@ def __init__(self): max_overflow=settings.DB_POOL_OVERFLOW, poolclass=SQLAlchemyQueuePool, ) - self.async_session: SQLAlchemyAsyncSessionMaker = SQLAlchemyAsyncSessionMaker(bind=self.async_engine , expire_on_commit=False) + self.async_session: SQLAlchemyAsyncSessionMaker = SQLAlchemyAsyncSessionMaker(bind=self.async_engine , expire_on_commit=False , class_=SQLAlchemyAsyncSession) self.pool: SQLAlchemyPool = self.async_engine.pool @property From aba8f54ce47c7af473741e67cd67ec90a429b92b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 26 Mar 2026 23:11:07 +0000 Subject: [PATCH 3/7] ci(pre-commit): Autofixing commit msg from pre-commit.com hooks --- backend/src/api/dependencies/session.py | 2 +- backend/src/repository/database.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/src/api/dependencies/session.py b/backend/src/api/dependencies/session.py index f8090f3..66d78d8 100644 --- a/backend/src/api/dependencies/session.py +++ b/backend/src/api/dependencies/session.py @@ -13,4 +13,4 @@ async def get_async_session() -> typing.AsyncGenerator[SQLAlchemyAsyncSession, None]: async with async_db.async_session as session: - yield session \ No newline at end of file + yield session diff --git a/backend/src/repository/database.py b/backend/src/repository/database.py index cd850b6..c46f354 100644 --- a/backend/src/repository/database.py +++ b/backend/src/repository/database.py @@ -23,7 +23,9 @@ def __init__(self): max_overflow=settings.DB_POOL_OVERFLOW, poolclass=SQLAlchemyQueuePool, ) - self.async_session: SQLAlchemyAsyncSessionMaker = SQLAlchemyAsyncSessionMaker(bind=self.async_engine , expire_on_commit=False , class_=SQLAlchemyAsyncSession) + self.async_session: SQLAlchemyAsyncSessionMaker = SQLAlchemyAsyncSessionMaker( + bind=self.async_engine, expire_on_commit=False, class_=SQLAlchemyAsyncSession + ) self.pool: SQLAlchemyPool = self.async_engine.pool @property From a2a22f9b491278e7fb7d63c223520c1646cc887d Mon Sep 17 00:00:00 2001 From: abdelrahman Date: Fri, 27 Mar 2026 01:25:28 +0200 Subject: [PATCH 4/7] opps i forgot () --- backend/src/api/dependencies/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/api/dependencies/session.py b/backend/src/api/dependencies/session.py index f8090f3..a692ebb 100644 --- a/backend/src/api/dependencies/session.py +++ b/backend/src/api/dependencies/session.py @@ -12,5 +12,5 @@ async def get_async_session() -> typing.AsyncGenerator[SQLAlchemyAsyncSession, None]: - async with async_db.async_session as session: + async with async_db.async_session() as session: yield session \ No newline at end of file From 4d854cce18bf47e007defe1eec28a62d0f57d3df Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 26 Mar 2026 23:33:07 +0000 Subject: [PATCH 5/7] ci(pre-commit): Autofixing commit msg from pre-commit.com hooks --- backend/src/api/dependencies/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/api/dependencies/session.py b/backend/src/api/dependencies/session.py index 374e8fc..a2fa985 100644 --- a/backend/src/api/dependencies/session.py +++ b/backend/src/api/dependencies/session.py @@ -12,5 +12,5 @@ async def get_async_session() -> typing.AsyncGenerator[SQLAlchemyAsyncSession, None]: - async with async_db.async_session() as session: + async with async_db.async_session() as session: yield session From a5b854df3ce2f6af18eb8e5e9e7a0058afe0db3e Mon Sep 17 00:00:00 2001 From: abdelrahman Date: Fri, 27 Mar 2026 01:45:48 +0200 Subject: [PATCH 6/7] fix typo in Dockerfile --- backend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 4517b16c261890378ba86cbac4bef9f640c7df3b Mon Sep 17 00:00:00 2001 From: abdelrahman Date: Fri, 27 Mar 2026 01:48:34 +0200 Subject: [PATCH 7/7] fix typo in README.md --- backend/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ---