Fix(vendor): close db session when vendor not found in get_vendor_details#258
Open
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Open
Fix(vendor): close db session when vendor not found in get_vendor_details#258Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Conversation
…ails 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes database session leak in
get_vendor_details()when vendor ID is not found (#144)Problem
When
get_vendor_details()is called with an invalid vendor ID, it raisesValueError("Vendor not found")but fails to close the database session.This leaks connections, causing connection pool exhaustion under load.
Root Cause
The function uses manual session management (
db = next(get_db())) withoutexception safety. When the exception is raised, execution jumps to the
caller without calling
db.close().Solution
Wrap the database operations in a try/finally block to guarantee
db.close()is called on all execution paths, including error paths.Impact
Testing
test_vnd_get_004_db_session_not_closed_on_exceptionnow passestest_vnd_get_*tests continue to passFixes #144