From aefb48e363dc0d0168f2c62b345b76585a3b590a Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 20 Apr 2023 20:10:30 +0100 Subject: [PATCH] Fix options inclusion constraint regression --- packages/server/src/api/controllers/table/utils.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/controllers/table/utils.ts b/packages/server/src/api/controllers/table/utils.ts index 1e57707cd0..1a3eda683b 100644 --- a/packages/server/src/api/controllers/table/utils.ts +++ b/packages/server/src/api/controllers/table/utils.ts @@ -110,19 +110,25 @@ export function importToRows( table: Table, user: ContextUser | null = null ) { + let originalTable = table let finalData: any = [] for (let i = 0; i < data.length; i++) { let row = data[i] row._id = generateRowID(table._id!) row.tableId = table._id + + // We use a reference to table here and update it after input processing, + // so that we can auto increment auto IDs in imported data properly const processed = inputProcessing(user, table, row, { noAutoRelationships: true, }) row = processed.row table = processed.table - for (const [fieldName, schema] of Object.entries(table.schema)) { - // check whether the options need to be updated for inclusion as part of the data import + // However here we must reference the original table, as we want to mutate + // the real schema of the table passed in, not the clone used for + // incrementing auto IDs + for (const [fieldName, schema] of Object.entries(originalTable.schema)) { if ( (schema.type === FieldTypes.OPTIONS || schema.type === FieldTypes.ARRAY) &&