Only throw on creation or primary display edition

This commit is contained in:
Adria Navarro 2024-12-18 13:32:09 +01:00
parent 59bdae57cc
commit 3a36289306
1 changed files with 13 additions and 6 deletions

View File

@ -68,17 +68,24 @@ function checkDefaultFields(table: Table) {
} }
} }
function guardTable(table: Table) { async function guardTable(table: Table, isCreate: boolean) {
checkDefaultFields(table) checkDefaultFields(table)
if ( if (
table.primaryDisplay && table.primaryDisplay &&
!canBeDisplayColumn(table.schema[table.primaryDisplay]?.type) !canBeDisplayColumn(table.schema[table.primaryDisplay]?.type)
) { ) {
throw new HTTPError( // Prevent throwing errors from existing badly configured tables. Only throw for new tables or if this setting is being updated
`Column "${table.primaryDisplay}" cannot be used as a display type.`, if (
400 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<SaveTableRequest, SaveTableResponse>) {
const isCreate = !table._id const isCreate = !table._id
guardTable(table) await guardTable(table, isCreate)
let savedTable: Table let savedTable: Table
if (isCreate) { if (isCreate) {