Skip to content

Commit 60b15cc

Browse files
fix(tables): block multiple→single select switch when cells have >1 option
Switching a select column from multiple to single would silently keep only the first option of any multi-valued cell. updateColumnOptions now scans the rows on that transition and errors ("N row(s) have multiple options selected") instead of dropping data, mirroring the type-change compatibility guard.
1 parent d55f94b commit 60b15cc

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

apps/sim/lib/table/columns/service.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,38 @@ export async function updateColumnOptions(
686686
throw new Error(`Cannot set options on column "${column.name}" of type "${column.type}"`)
687687
}
688688

689+
// Switching multiple → single would silently drop all but the first option
690+
// in any multi-valued cell — block it instead, mirroring the type-change
691+
// compatibility guard.
692+
const willBeMultiple = data.multiple ?? column.multiple
693+
if (column.multiple && !willBeMultiple) {
694+
const timeoutMs = scaledStatementTimeoutMs(table.rowCount ?? 0, {
695+
baseMs: 60_000,
696+
perRowMs: 2,
697+
})
698+
await setTableTxTimeouts(trx, { statementMs: timeoutMs, idleMs: timeoutMs })
699+
700+
const columnKey = getColumnId(column)
701+
const rows = await trx
702+
.select({ data: userTableRows.data })
703+
.from(userTableRows)
704+
.where(
705+
and(eq(userTableRows.tableId, data.tableId), sql`${userTableRows.data} ? ${columnKey}`)
706+
)
707+
708+
let multiValuedCount = 0
709+
for (const row of rows) {
710+
const value = (row.data as RowData)[columnKey]
711+
if (Array.isArray(value) && value.length > 1) multiValuedCount++
712+
}
713+
714+
if (multiValuedCount > 0) {
715+
throw new Error(
716+
`Cannot switch column "${column.name}" to single-select: ${multiValuedCount} row(s) have multiple options selected. Reduce them to one option first.`
717+
)
718+
}
719+
}
720+
689721
const { multiple: _prevMultiple, ...columnRest } = column
690722
const updatedColumn = {
691723
...columnRest,

0 commit comments

Comments
 (0)