Making sure all protected columns are kept during row save/patch operations.

This commit is contained in:
mike12345567 2024-11-04 13:33:12 +00:00 committed by Adria Navarro
parent b8c10d4765
commit 6edaf5e160
2 changed files with 14 additions and 4 deletions

View File

@ -31,6 +31,8 @@ import {
import { isExternalTableID } from "../../integrations/utils"
import {
helpers,
isExternalColumnName,
isInternalColumnName,
PROTECTED_EXTERNAL_COLUMNS,
PROTECTED_INTERNAL_COLUMNS,
} from "@budibase/shared-core"
@ -202,14 +204,18 @@ export async function inputProcessing(
const clonedRow = cloneDeep(row)
const table = await getTableFromSource(source)
const dontCleanseKeys = ["type", "_id", "_rev", "tableId"]
for (const [key, value] of Object.entries(clonedRow)) {
const field = table.schema[key]
// cleanse fields that aren't in the schema
if (
!field && isExternalTableID(table._id!)
? !isExternalColumnName(key)
: !isInternalColumnName(key)
) {
delete clonedRow[key]
}
// field isn't found - might be a built-in column, skip over it
if (!field) {
if (dontCleanseKeys.indexOf(key) === -1) {
delete clonedRow[key]
}
continue
}
// remove any formula values, they are to be generated

View File

@ -12,3 +12,7 @@ export const PROTECTED_EXTERNAL_COLUMNS = ["_id", "_rev", "tableId"] as const
export function isInternalColumnName(name: string): boolean {
return (PROTECTED_INTERNAL_COLUMNS as readonly string[]).includes(name)
}
export function isExternalColumnName(name: string): boolean {
return (PROTECTED_EXTERNAL_COLUMNS as readonly string[]).includes(name)
}