From b4873f8ebf6ce00e8b65df2208aca55068ec09ad Mon Sep 17 00:00:00 2001 From: JEAN REGIS <240509606@firat.edu.tr> Date: Wed, 18 Mar 2026 18:05:06 +0300 Subject: [PATCH] fix(vendor): close db session when vendor not found in get_vendor_details Root cause: get_vendor_details() uses manual session management (next(get_db())) but lacks exception safety. When ValueError is raised for non-existent vendor, the session is never closed, causing connection leaks. Solution: Wrap database operations in try/finally block to ensure db.close() is called on all execution paths, including error paths. Impact: - Zero behavioral changes on success path - Sessions now properly closed on error path - Prevents connection pool exhaustion under load - Matches fix pattern from similar issue INV-GET-004 Signed-off-by: JEAN REGIS <240509606@firat.edu.tr> --- finbot/tools/data/vendor.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/finbot/tools/data/vendor.py b/finbot/tools/data/vendor.py index 7cac2cd3..f708a480 100644 --- a/finbot/tools/data/vendor.py +++ b/finbot/tools/data/vendor.py @@ -23,13 +23,15 @@ async def get_vendor_details( Dictionary containing vendor details """ logger.info("Getting vendor details for vendor_id: %s", vendor_id) - with db_session() as db: + db = next(get_db()) + try: vendor_repo = VendorRepository(db, session_context) vendor = vendor_repo.get_vendor(vendor_id) if not vendor: raise ValueError("Vendor not found") return vendor.to_dict() - + finally: + db.close() async def get_vendor_contact_info( vendor_id: int,