From 681674925705b9e479460454f17bba26388d36e5 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 3 Apr 2023 17:16:39 +0800 Subject: [PATCH] fix(nocodb): bulk delete transaction issue --- .../lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts index 05038999cc..d154aea3c8 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts @@ -2203,10 +2203,7 @@ class BaseModelSqlv2 { ids.map((d) => this.model.mapAliasToColumn(d)) ); - transaction = await this.dbDriver.transaction(); - const deleted = []; - const deletePkValues = []; const res = []; for (const d of deleteIds) { const pkValues = await this._extractPksValues(d); @@ -2214,13 +2211,14 @@ class BaseModelSqlv2 { // pk not specified - bypass continue; } - deletePkValues.push(pkValues); - await transaction(this.tnPath).del().where(d); + deleted.push(await this.readByPk(pkValues)); res.push(d); } - for (const pkValues of deletePkValues) { - deleted.push(await this.readByPk(pkValues)); + transaction = await this.dbDriver.transaction(); + + for (const d of res) { + await transaction(this.tnPath).del().where(d); } await transaction.commit();