From 3a36289306e65b1e3889b8750adf17e1ca22e478 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 18 Dec 2024 13:32:09 +0100 Subject: [PATCH] Only throw on creation or primary display edition --- .../server/src/api/controllers/table/index.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/server/src/api/controllers/table/index.ts b/packages/server/src/api/controllers/table/index.ts index 76102b9be4..06d44bc41c 100644 --- a/packages/server/src/api/controllers/table/index.ts +++ b/packages/server/src/api/controllers/table/index.ts @@ -68,17 +68,24 @@ function checkDefaultFields(table: Table) { } } -function guardTable(table: Table) { +async function guardTable(table: Table, isCreate: boolean) { checkDefaultFields(table) if ( table.primaryDisplay && !canBeDisplayColumn(table.schema[table.primaryDisplay]?.type) ) { - throw new HTTPError( - `Column "${table.primaryDisplay}" cannot be used as a display type.`, - 400 - ) + // Prevent throwing errors from existing badly configured tables. Only throw for new tables or if this setting is being updated + if ( + isCreate || + (await sdk.tables.getTable(table._id!)).primaryDisplay !== + table.primaryDisplay + ) { + throw new HTTPError( + `Column "${table.primaryDisplay}" cannot be used as a display type.`, + 400 + ) + } } } @@ -126,7 +133,7 @@ export async function save(ctx: UserCtx) { const isCreate = !table._id - guardTable(table) + await guardTable(table, isCreate) let savedTable: Table if (isCreate) {