mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 01:14:31 +02:00
Fix failed db.execute() write leaves a phantom transaction open
Refs https://github.com/simonw/sqlite-utils/issues/769#issuecomment-4900034150
This commit is contained in:
parent
f2fbcf60d8
commit
7d86118168
3 changed files with 54 additions and 4 deletions
|
|
@ -870,10 +870,18 @@ class Database:
|
|||
if self._tracer:
|
||||
self._tracer(sql, parameters)
|
||||
was_in_transaction = self.conn.in_transaction
|
||||
if parameters is not None:
|
||||
cursor = self.conn.execute(sql, parameters)
|
||||
else:
|
||||
cursor = self.conn.execute(sql)
|
||||
try:
|
||||
if parameters is not None:
|
||||
cursor = self.conn.execute(sql, parameters)
|
||||
else:
|
||||
cursor = self.conn.execute(sql)
|
||||
except Exception:
|
||||
if not was_in_transaction and self.conn.in_transaction:
|
||||
# The failed statement opened an implicit transaction that
|
||||
# nothing would ever commit - roll it back, otherwise it
|
||||
# would capture every subsequent write
|
||||
self.conn.execute("ROLLBACK")
|
||||
raise
|
||||
if (
|
||||
not was_in_transaction
|
||||
and self.conn.in_transaction
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue