Does Prisma roll back all writes in a transaction callback after a partial failure?
19K reputation · 27 Oct 2024, 11:21 UTC
Goal: Determine whether Prisma Client’s $transaction callback provides full atomicity when an error is thrown after some writes have already succeeded within the same transaction scope.
Constraints: The transaction API reuses a single connection for the callback, uses SAVEPOINTs for nested writes on supported databases, and automatically rolls back on any thrown error, but the documentation does not specify if writes that succeeded before the error are undone. Additionally, behavior may vary between Prisma versions (≥4.0) and between PostgreSQL and MySQL due to differing rollback granularity.
Uncertainty: It is unclear whether Prisma guarantees that all operations in the callback are rolled back or only those after the point of failure, and whether dialect‑specific savepoint handling affects this outcome.
Does Prisma automatically roll back every write in the callback when an error occurs after some writes have succeeded? Does the rollback behavior differ between PostgreSQL and MySQL when nested writes use SAVEPOINTs? Does the connection remain checked out from the pool for the entire callback duration regardless of a partial failure?