From e3980d072aec1181819cfa86b47512aafe170a5e Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 4 Oct 2022 17:54:33 +0100 Subject: [PATCH] Fixing a regression of CSV table creation - normally if a CSV was used to create a table with an options column all of the options would be filled in but this had been broken. --- packages/server/src/api/controllers/public/utils.ts | 2 +- .../server/src/api/controllers/table/internal.ts | 12 ++++++++++-- packages/server/src/api/controllers/table/utils.ts | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) 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 }