From bc6108f83fa99a69752778253761d763a0b99db4 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 26 Jul 2023 09:52:11 +0300 Subject: Commit changes on success, rollback on failure. Ensure that changes the database are committed if the query is successful, or rolled back if not. --- wqflask/wqflask/database.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'wqflask') diff --git a/wqflask/wqflask/database.py b/wqflask/wqflask/database.py index ad2d8216..0c1fddf1 100644 --- a/wqflask/wqflask/database.py +++ b/wqflask/wqflask/database.py @@ -40,5 +40,9 @@ def database_connection(sql_uri: str) -> Iterator[Connection]: ) try: yield connection + connection.commit() + except Exception as _exc: + connection.rollback() + raise _exc finally: connection.close() -- cgit v1.2.3