From 89fdf3d833caa34e7fc1813cdae2aa1b139bd50b Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Fri, 26 May 2023 11:18:05 +0530 Subject: [PATCH] fix: rollback transaction if bulk insert errors Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com> --- packages/nocodb/src/db/BaseModelSqlv2.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index f7ddc9db94..2d25a11e08 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -2091,6 +2091,7 @@ class BaseModelSqlv2 { raw?: boolean; } = {}, ) { + let trx; try { // TODO: ag column handling for raw bulk insert const insertDatas = raw @@ -2115,7 +2116,7 @@ class BaseModelSqlv2 { // refer : https://www.sqlite.org/limits.html const chunkSize = this.isSqlite ? 10 : _chunkSize; - const trx = await this.dbDriver.transaction(); + trx = await this.dbDriver.transaction(); if (!foreign_key_checks) { if (this.isPg) { @@ -2146,6 +2147,7 @@ class BaseModelSqlv2 { return response; } catch (e) { + await trx?.rollback(); // await this.errorInsertb(e, data, null); throw e; }