aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-12-06 12:47:00 -0600
committerFrederick Muriuki Muriithi2024-12-06 12:47:00 -0600
commitf9caab321d56342a5cc330611ed18c38c643ed28 (patch)
tree01f928addfb2457d83396edaccd037152e31cfbc
parent4d9a29862a34b6b91829b3504b339214d010d722 (diff)
downloadgn-libs-f9caab321d56342a5cc330611ed18c38c643ed28.tar.gz
Move the commit() call to the success path
The `finally` clause gets run whether or not the try succeeds. It only makes sense to run the commit on success, so we move it into the try, just after yielding the connection.
-rw-r--r--gn_libs/mysqldb.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/gn_libs/mysqldb.py b/gn_libs/mysqldb.py
index 11302a2..be21550 100644
--- a/gn_libs/mysqldb.py
+++ b/gn_libs/mysqldb.py
@@ -87,11 +87,11 @@ def database_connection(sql_uri: str, logger: logging.Logger = _logger) -> Itera
connection = mdb.connect(**parse_db_url(sql_uri))
try:
yield connection
+ connection.commit()
except mdb.Error as _mbde:
logger.error("DB error encountered", exc_info=True)
connection.rollback()
finally:
- connection.commit()
connection.close()