Skip to content

Commit

Permalink
Fix: release sessions even in case of error.
Browse files Browse the repository at this point in the history
  • Loading branch information
MBogda committed Dec 17, 2024
1 parent 0034d94 commit 37740c2
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions ydb_sqlalchemy/dbapi/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,24 @@ def begin(self):
self._maybe_await(self.tx_context.begin)

def commit(self):
if self.tx_context and self.tx_context.tx_id:
self._maybe_await(self.tx_context.commit)
self.tx_context = None
if self.session:
self._maybe_await(self.session_pool.release, self.session)
self.session = None
try:
if self.tx_context and self.tx_context.tx_id:
self._maybe_await(self.tx_context.commit)
self.tx_context = None
finally:
if self.session:
self._maybe_await(self.session_pool.release, self.session)
self.session = None

def rollback(self):
if self.tx_context and self.tx_context.tx_id:
self._maybe_await(self.tx_context.rollback)
self.tx_context = None
if self.session:
self._maybe_await(self.session_pool.release, self.session)
self.session = None
try:
if self.tx_context and self.tx_context.tx_id:
self._maybe_await(self.tx_context.rollback)
self.tx_context = None
finally:
if self.session:
self._maybe_await(self.session_pool.release, self.session)
self.session = None

def close(self):
self.rollback()
Expand Down

0 comments on commit 37740c2

Please sign in to comment.