Skip to content

Commit 0674b7c

Browse files
author
Kareem Zidane
committed
delete transaction connection on failure
1 parent 7bf7e16 commit 0674b7c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/cs50/sql.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ def _execute(self, statement, connection):
6363
raise ValueError(exc.orig) from None
6464
# E.g., connection error or syntax error
6565
except (sqlalchemy.exc.OperationalError, sqlalchemy.exc.ProgrammingError) as exc:
66-
connection.close()
66+
if self._engine.get_existing_transaction_connection():
67+
self._engine.close_transaction_connection()
68+
else:
69+
connection.close()
6770
_logger.debug(red(statement))
6871
raise RuntimeError(exc.orig) from None
6972

0 commit comments

Comments
 (0)