From 13defb86044ab61603c1672789e6697ed112e6b2 Mon Sep 17 00:00:00 2001 From: Cody Fincher Date: Sun, 8 Feb 2026 01:05:19 +0000 Subject: [PATCH] fix(aiosqlite): commit pending transactions on pool release instead of rolling back The aiosqlite pool unconditionally rolled back on connection release, silently discarding DML changes made without explicit commit. This caused INSERT ... RETURNING to appear successful but never persist. Align with the sqlite adapter by committing if in_transaction on release. --- sqlspec/adapters/aiosqlite/pool.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sqlspec/adapters/aiosqlite/pool.py b/sqlspec/adapters/aiosqlite/pool.py index fae8ccf1..f663b2fa 100644 --- a/sqlspec/adapters/aiosqlite/pool.py +++ b/sqlspec/adapters/aiosqlite/pool.py @@ -679,10 +679,11 @@ async def release(self, connection: AiosqlitePoolConnection) -> None: return try: - # Fast path: skip timeout wrapper for reset, just do the rollback directly - # The rollback itself is fast for SQLite; timeout is overkill for hot path + # Auto-commit pending transactions on release (matches sqlite adapter behavior). + # Without this, DML executed outside explicit begin/commit is silently rolled back. with suppress(Exception): - await connection.connection.rollback() + if connection.connection.in_transaction: + await connection.connection.commit() connection.idle_since = time.time() # mark_as_idle inline self._queue.put_nowait(connection) except Exception as e: