Skip to content

Commit e6e136a

Browse files
fix: prevent transaction rollback error at teardown (#68)
1 parent ac7b115 commit e6e136a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,3 +685,15 @@ def get_isolation_level(self, conn_proxy):
685685
conn = conn_proxy.connection
686686

687687
return "AUTOCOMMIT" if conn.autocommit else "SERIALIZABLE"
688+
689+
def do_rollback(self, dbapi_connection):
690+
"""To prevent transaction rollback error, rollback is ignored if
691+
DBAPI rollback is already executed."""
692+
if (
693+
not isinstance(dbapi_connection, spanner_dbapi.Connection)
694+
and dbapi_connection.connection._transaction
695+
and dbapi_connection.connection._transaction.rolled_back
696+
):
697+
pass
698+
else:
699+
dbapi_connection.rollback()

0 commit comments

Comments
 (0)