Skip to content

Commit

Permalink
Move connection.closed check to SAConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
Pliner committed Mar 22, 2021
1 parent 5c4f92e commit 7bb9434
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
23 changes: 15 additions & 8 deletions aiopg/sa/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,15 @@ async def _commit_impl(self):
self._transaction = None

async def _rollback_impl(self):
cursor = await self._open_cursor()
try:
await cursor.execute('ROLLBACK')
if self._connection.closed:
return
cursor = await self._open_cursor()
try:
await cursor.execute('ROLLBACK')
finally:
self._close_cursor(cursor)
finally:
self._close_cursor(cursor)
self._transaction = None

def begin_nested(self):
Expand Down Expand Up @@ -268,13 +272,16 @@ async def _savepoint_impl(self):
self._close_cursor(cursor)

async def _rollback_to_savepoint_impl(self, name, parent):
cursor = await self._open_cursor()
try:
await cursor.execute(f'ROLLBACK TO SAVEPOINT {name}')
if self._connection.closed:
return
cursor = await self._open_cursor()
try:
await cursor.execute(f'ROLLBACK TO SAVEPOINT {name}')
finally:
self._close_cursor(cursor)
finally:
self._close_cursor(cursor)

self._transaction = parent
self._transaction = parent

async def _release_savepoint_impl(self, name, parent):
cursor = await self._open_cursor()
Expand Down
4 changes: 2 additions & 2 deletions aiopg/sa/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def close(self):
This is used to cancel a Transaction without affecting the scope of
an enclosing transaction.
"""
if not self._parent._is_active or self._connection.closed:
if not self._parent._is_active:
return
if self._parent is self:
await self.rollback()
Expand All @@ -60,7 +60,7 @@ async def close(self):

async def rollback(self):
"""Roll back this transaction."""
if not self._parent._is_active or self._connection.closed:
if not self._parent._is_active:
return
await self._do_rollback()
self._is_active = False
Expand Down

0 comments on commit 7bb9434

Please sign in to comment.