diff --git a/packages/server/src/api/controllers/public/utils.ts b/packages/server/src/api/controllers/public/utils.ts index d86eced9ba..6909db9628 100644 --- a/packages/server/src/api/controllers/public/utils.ts +++ b/packages/server/src/api/controllers/public/utils.ts @@ -22,7 +22,7 @@ export async function addRev( } /** - * Performs a case insensitive search on the provided documents, using the + * Performs a case in-sensitive search on the provided documents, using the * provided key and value. This will be a string based search, using the * startsWith function. */ diff --git a/packages/server/src/api/controllers/table/internal.ts b/packages/server/src/api/controllers/table/internal.ts index 03e2cc056c..71f6fb5224 100644 --- a/packages/server/src/api/controllers/table/internal.ts +++ b/packages/server/src/api/controllers/table/internal.ts @@ -14,8 +14,10 @@ import { fixAutoColumnSubType, } from "../../../utilities/rowProcessor" import { runStaticFormulaChecks } from "./bulkFormula" -import { Table } from "../../../definitions/common" +import { Table } from "@budibase/types" import { quotas } from "@budibase/pro" +import { isEqual } from "lodash" +import { cloneDeep } from "lodash/fp" function checkAutoColumns(table: Table, oldTable: Table) { if (!table.schema) { @@ -123,10 +125,16 @@ export async function save(ctx: any) { if (updatedRows && updatedRows.length !== 0) { await db.bulkDocs(updatedRows) } - const result = await db.put(tableToSave) + let result = await db.put(tableToSave) tableToSave._rev = result.rev + const savedTable = cloneDeep(tableToSave) tableToSave = await tableSaveFunctions.after(tableToSave) + // the table may be updated as part of the table save after functionality - need to write it + if (!isEqual(savedTable, tableToSave)) { + result = await db.put(tableToSave) + tableToSave._rev = result.rev + } // has to run after, make sure it has _id await runStaticFormulaChecks(tableToSave, { oldTable, deletion: null }) return tableToSave diff --git a/packages/server/src/api/controllers/table/utils.ts b/packages/server/src/api/controllers/table/utils.ts index 896221dddf..cbad2afea5 100644 --- a/packages/server/src/api/controllers/table/utils.ts +++ b/packages/server/src/api/controllers/table/utils.ts @@ -245,7 +245,7 @@ class TableSaveFunctions { // after saving async after(table: any) { table = await handleSearchIndexes(table) - await handleDataImport(this.user, table, this.dataImport) + table = await handleDataImport(this.user, table, this.dataImport) return table }