aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-05-19 16:52:05 -0500
committerFrederick Muriuki Muriithi2025-05-19 16:52:05 -0500
commitc0fb1e6001a0d059f71032279e6c6ba590d35b1a (patch)
tree66f9dae86fbf529b569d82780d96d292fd9ece8e
parent92eda6bb0002f47f8763530720d0c8321423466e (diff)
downloadgn-libs-c0fb1e6001a0d059f71032279e6c6ba590d35b1a.tar.gz
Handle generic exception occurring while using the connection
Rollback any transaction if any exception occurs before the connection is closed.
-rw-r--r--gn_libs/mysqldb.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/gn_libs/mysqldb.py b/gn_libs/mysqldb.py
index eabd1e1..2fd0f00 100644
--- a/gn_libs/mysqldb.py
+++ b/gn_libs/mysqldb.py
@@ -132,6 +132,10 @@ def database_connection(sql_uri: str, logger: logging.Logger = _logger) -> Itera
logger.error("DB error encountered", exc_info=True)
connection.rollback()
raise _mbde from None
+ except:
+ logger.error("General exception encountered", exc_info=True)
+ connection.rollback()
+ raise _exc from None
finally:
connection.close()