From e475a4a2c1888f9335df1bfc4b773670c3ab1dd3 Mon Sep 17 00:00:00 2001 From: luxferre Date: Wed, 13 May 2026 11:49:51 +0100 Subject: [PATCH] feat: db dependency modification No longer using begin() and context manager. This means commits must be explicit (already were) but also, it allows for sanity checks within routes after commits. --- src/database.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/database.py b/src/database.py index 9b4a199..d6b5a55 100644 --- a/src/database.py +++ b/src/database.py @@ -19,12 +19,14 @@ engine = create_engine(SQLALCHEMY_DATABASE_URI.get_secret_value()) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) def get_db(): - with SessionLocal.begin() as db: - try: - yield db - finally: - db.rollback() # Anything not explicitly commited is rolled back - db.close() + db = SessionLocal() + try: + yield db + except: + db.rollback() + raise + finally: + db.close() db_dependency = Annotated[Session, Depends(get_db)]