Repository navigation
Description
Summary
#7108 gave Database.run_in_transaction() in the Python bindings a BaseException handler that rolls back,
so an ordinary bug in the callable cannot leave an open transaction for the next caller to inherit. The same
class has a second begin()/commit() site that was not touched: the per-row fallback inside
Database.insert_many(). It calls begin() and then loops new_document / set / save / commit with no
try/finally and no rollback path at all.
That branch is entered precisely when json.dumps(rows) has already raised, i.e. when the rows contain values
the fast path could not serialise. Those are the rows most likely to make doc.set(k, v) raise in turn, so
the unprotected path is the one with the highest chance of throwing.
Where (HEAD 06b033d)
bindings/python/src/arcadedb_embedded/core.py:263-284:
try:
payload = _json.dumps(rows)
except (TypeError, ValueError):
# Non-JSON-representable values (note: numpy integer scalars land
# here too, since json.dumps rejects np.int64): per-row fallback,
# honoring commit_every batches like the fast path.
n = 0
was_active = self.is_transaction_active()
if not was_active:
self.begin()
for row in rows:
doc = self.new_document(type_name)
for k, v in row.items():
doc.set(k, v)
doc.save()
n += 1
if not was_active and commit_every > 0 and n % commit_every == 0:
self.commit()
self.begin()
if not was_active:
self.commit()
return nFor contrast, the site #7108 fixed, core.py:152-180:
for attempt in range(retries + 1):
self.begin()
try:
result = fn()
self.commit()
return result
except BaseException as e:
# Any exit path other than a successful commit must roll back,
# not just ArcadeDBError - matching LocalDatabase.transaction()'s
# `catch (final Throwable e)` on the Java side (#7108). An
# ordinary bug in fn() (TypeError, KeyError, ...) must not leave
# an open transaction for the next caller to inherit, and neither
# must KeyboardInterrupt/SystemExit, which `except Exception`
# does not catch (code review on #7108).
try:
if self.is_transaction_active():
self.rollback()
except Exception: # nosec B110 - best-effort rollback before retry
passRepro
db.insert_many("Doc", [{"a": datetime.now()}, {"b": SomethingUnsettable()}])json.dumpsrejects thedatetime, so the fallback branch runs.was_activeisFalse,begin()opens a transaction.doc.set("b", ...)raises on the second row.- The exception propagates out of
insert_manywith the transaction still open, holding the first row's
write.
Whatever the caller does next runs inside that inherited transaction: a later commit() publishes a partial
batch the caller believes was never written, and a later begin() on an already-active transaction is a
second surprise. With the commit_every loop the window is worse, because the batches committed before the
failure are already durable while the caller sees only an exception.
Suggested fix
Wrap the loop so that any exit path other than the successful commit() rolls back when was_active is
False, mirroring run_in_transaction:
if not was_active:
self.begin()
try:
...
if not was_active:
self.commit()
return n
except BaseException:
if not was_active:
try:
if self.is_transaction_active():
self.rollback()
except Exception: # nosec B110 - best-effort rollback
pass
raiseBaseException rather than Exception, for the reason the #7108 review gave: KeyboardInterrupt and
SystemExit must not leave a transaction open either.
Separately, bindings/python/src/arcadedb_embedded/graph_batch.py:139 catches only Exception around its own
begin()/commit() pair in GraphBatch.create_vertex(), so a KeyboardInterrupt between the begin() at
:125 and the commit() at :136 leaks the transaction it started. Same reasoning, same one-word change.
Scope / confidence
Checked at HEAD 06b033d: bindings/python/src/arcadedb_embedded/core.py is untouched since the #7108
fix, and these are the only two begin() sites in the file. The was_active guard means an
insert_many called from inside a caller's own transaction does not commit or roll back the caller's work,
which the suggested fix preserves. No issue in the last 1000 covers insert_many; #7108 is the sibling and
is closed.
What would falsify it: if doc.set() could not raise for a value that json.dumps rejected. It can, and the
branch's own comment names np.int64 as a value that reaches it, which is a type the Java side has to be
able to convert.
Activity
fix(#7882): roll back insert_many and GraphBatch.create_vertex transa…
fix(#7882): roll back insert_many and GraphBatch.create_vertex transa…
fix(#7882): roll back insert_many and GraphBatch.create_vertex transa…
robfrank commentedon Oct 22, 2026
Fixed by #8828.
Database.insert_many()could leave a transaction open after a failure: its per-row fallback (used when the rows cannot be JSON-encoded, for exampledatetimeornp.int64values) had no rollback, and the JSON fast path had the same leak, for example on a mandatory-property validation failure. Both paths now roll back the transaction they opened on every failure, includingKeyboardInterrupt, andGraphBatch.create_vertex()now rolls back onKeyboardInterruptandSystemExittoo, which still propagate unwrapped while ordinary failures are still wrapped inArcadeDBError. One behaviour change: wheninsert_manyruns inside a transaction you opened yourself, the fast path no longer commits it everycommit_everyrows, matching what the fallback already did.Still open: nothing, the fix is complete. With
commit_every > 0and no transaction of your own, batches committed before a failure stay committed; only the open batch is rolled back.❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.