Skip to content

Commit

Permalink
Don't commit if there was an exception
Browse files Browse the repository at this point in the history
  • Loading branch information
RisingOrange committed Dec 20, 2023
1 parent c711334 commit e73d613
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ankihub/db/db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ def _execute_inner(self, sql: str, *args, first_row_only=False) -> List:
except Exception as e:
LOGGER.info(f"Error while executing SQL: {sql}")
raise e
finally:
else:
if not self._is_used_as_context_manager:
self._conn.commit()
finally:
if not self._is_used_as_context_manager:
self._conn.close()

return result
Expand Down Expand Up @@ -71,7 +73,9 @@ def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self._conn.commit()
if exc_type is None:
self._conn.commit()

self._conn.close()
self._is_used_as_context_manager = False
self._lock_context.__exit__(exc_type, exc_val, exc_tb)

0 comments on commit e73d613

Please sign in to comment.