1
0
Fork 0
mirror of synced 2024-06-27 02:20:35 +12:00

Fixing issue with formula column validation breaking row save.

This commit is contained in:
mike12345567 2022-02-21 15:01:42 +00:00
parent 39aed46754
commit cf9664969f
2 changed files with 5 additions and 10 deletions

View file

@ -84,10 +84,7 @@ export const FIELDS = {
FORMULA: {
name: "Formula",
type: "formula",
constraints: {
type: "string",
presence: false,
},
constraints: {},
},
JSON: {
name: "JSON",

View file

@ -3,7 +3,6 @@ const { cloneDeep } = require("lodash/fp")
const { InternalTables } = require("../../../db/utils")
const userController = require("../user")
const { FieldTypes } = require("../../../constants")
const { processStringSync } = require("@budibase/string-templates")
const { makeExternalQuery } = require("../../../integrations/base/utils")
const { getAppDB } = require("@budibase/backend-core/context")
@ -52,6 +51,10 @@ exports.validate = async ({ tableId, row, table }) => {
for (let fieldName of Object.keys(table.schema)) {
const constraints = cloneDeep(table.schema[fieldName].constraints)
const type = table.schema[fieldName].type
// formulas shouldn't validated, data will be deleted anyway
if (type === FieldTypes.FORMULA) {
continue
}
// special case for options, need to always allow unselected (null)
if (type === FieldTypes.OPTIONS && constraints.inclusion) {
constraints.inclusion.push(null)
@ -77,11 +80,6 @@ exports.validate = async ({ tableId, row, table }) => {
} catch (err) {
errors[fieldName] = [`Contains invalid JSON`]
}
} else if (type === FieldTypes.FORMULA) {
res = validateJs.single(
processStringSync(table.schema[fieldName].formula, row),
constraints
)
} else {
res = validateJs.single(row[fieldName], constraints)
}