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.
This commit is contained in:
Chris Milne 2026-05-13 11:49:51 +01:00
parent f6a292f173
commit e475a4a2c1

View file

@ -19,12 +19,14 @@ engine = create_engine(SQLALCHEMY_DATABASE_URI.get_secret_value())
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
def get_db(): def get_db():
with SessionLocal.begin() as db: db = SessionLocal()
try: try:
yield db yield db
finally: except:
db.rollback() # Anything not explicitly commited is rolled back db.rollback()
db.close() raise
finally:
db.close()
db_dependency = Annotated[Session, Depends(get_db)] db_dependency = Annotated[Session, Depends(get_db)]