Fix delete_where() leaving the connection in an open transaction

Table.delete_where() ran its DELETE via a bare execute() with no
commit, unlike Table.delete() which wraps in db.atomic(). The
connection was left with an open implicit transaction, so the
deletion (and all subsequent writes, including later atomic()
blocks which switched to savepoint mode) was silently rolled back
when the connection closed.

Wrap the DELETE in db.atomic() and remove the now-unnecessary
atomic() wrapper from the delete_where documentation example.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UnLnhsH25Nnv7LHhekUfPd
This commit is contained in:
Claude 2026-07-04 17:57:35 +00:00
commit b17c37144e
No known key found for this signature in database
3 changed files with 21 additions and 3 deletions

View file

@ -2966,7 +2966,8 @@ class Table(Queryable):
sql = "delete from {}".format(quote_identifier(self.name))
if where is not None:
sql += " where " + where
self.db.execute(sql, where_args or [])
with self.db.atomic():
self.db.execute(sql, where_args or [])
if analyze:
self.analyze()
return self