Enforcing squash for rows which contain circular structures.
This commit is contained in:
parent
c1f9ef1bce
commit
312415ca7d
|
@ -237,3 +237,17 @@ export function timeout(timeMs: number) {
|
|||
export function isAudited(event: Event) {
|
||||
return !!AuditedEventFriendlyName[event]
|
||||
}
|
||||
|
||||
export function hasCircularStructure(json: any) {
|
||||
if (typeof json !== "object") {
|
||||
return false
|
||||
}
|
||||
try {
|
||||
JSON.stringify(json)
|
||||
} catch (err) {
|
||||
if (err instanceof Error && err?.message.includes("circular structure")) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -2,16 +2,15 @@ import * as linkRows from "../../db/linkedRows"
|
|||
import { FieldTypes, AutoFieldSubTypes } from "../../constants"
|
||||
import { processFormulas, fixAutoColumnSubType } from "./utils"
|
||||
import { ObjectStoreBuckets } from "../../constants"
|
||||
import { context, db as dbCore, objectStore } from "@budibase/backend-core"
|
||||
import {
|
||||
context,
|
||||
db as dbCore,
|
||||
objectStore,
|
||||
utils,
|
||||
} from "@budibase/backend-core"
|
||||
import { InternalTables } from "../../db/utils"
|
||||
import { TYPE_TRANSFORM_MAP } from "./map"
|
||||
import {
|
||||
AutoColumnFieldMetadata,
|
||||
FieldSubtype,
|
||||
Row,
|
||||
RowAttachment,
|
||||
Table,
|
||||
} from "@budibase/types"
|
||||
import { FieldSubtype, Row, RowAttachment, Table } from "@budibase/types"
|
||||
import { cloneDeep } from "lodash/fp"
|
||||
import {
|
||||
processInputBBReferences,
|
||||
|
@ -233,6 +232,11 @@ export async function outputProcessing<T extends Row[] | Row>(
|
|||
})
|
||||
: safeRows
|
||||
|
||||
// make sure squash is enabled if needed
|
||||
if (!opts.squash && utils.hasCircularStructure(rows)) {
|
||||
opts.squash = true
|
||||
}
|
||||
|
||||
// process complex types: attachements, bb references...
|
||||
for (let [property, column] of Object.entries(table.schema)) {
|
||||
if (column.type === FieldTypes.ATTACHMENT) {
|
||||
|
|
Loading…
Reference in New Issue