Skip to content

Commit

Permalink
SQL.execute and AsyncSQL.execute better handle rollback outside of tr…
Browse files Browse the repository at this point in the history
…ansaction
  • Loading branch information
seanharrison committed Sep 17, 2023
1 parent 430c2f5 commit 92508ff
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions sqly/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,11 @@ def execute(
except Exception as exc:
# If the connection is a cursor, get the underlying connection to rollback,
# because cursors don't have a rollback method.
if hasattr(connection, "connection"):
connection = connection.connection
connection.rollback()
if hasattr(connection, "rollback"):
try:
connection.rollback()
except Exception:
...
raise exc

return cursor
Expand Down Expand Up @@ -238,9 +240,11 @@ async def execute(
except Exception as exc:
# If the connection is a cursor, get the underlying connection to rollback,
# because cursors don't have a rollback method.
if hasattr(connection, "connection"):
connection = connection.connection
await connection.rollback()
if hasattr(connection, "rollback"):
try:
await connection.rollback()
except Exception:
...
raise exc

return cursor
Expand Down

0 comments on commit 92508ff

Please sign in to comment.