Fix for circular issue with primary display fields on SQL tables introduced in most recent update - if somehow the primary display field is set to a relationship field there was a chance of cyclic structure occurring which Koa could not convert to JSON.
This commit is contained in:
parent
6158b4ac65
commit
68082eecf9
|
@ -19,6 +19,7 @@ import {
|
|||
breakRowIdField,
|
||||
convertRowId,
|
||||
generateRowIdField,
|
||||
getPrimaryDisplay,
|
||||
isRowId,
|
||||
isSQL,
|
||||
} from "../../../integrations/utils"
|
||||
|
@ -391,7 +392,10 @@ export class ExternalRequest {
|
|||
}
|
||||
}
|
||||
relatedRow = processFormulas(linkedTable, relatedRow)
|
||||
const relatedDisplay = display ? relatedRow[display] : undefined
|
||||
let relatedDisplay
|
||||
if (display) {
|
||||
relatedDisplay = getPrimaryDisplay(relatedRow[display])
|
||||
}
|
||||
row[relationship.column][key] = {
|
||||
primaryDisplay: relatedDisplay || "Invalid display column",
|
||||
_id: relatedRow._id,
|
||||
|
|
|
@ -328,3 +328,22 @@ export function finaliseExternalTables(
|
|||
.reduce((r, [k, v]) => ({ ...r, [k]: v }), {})
|
||||
return { tables: finalTables, errors }
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the provided input is an object, but specifically not a date type object.
|
||||
* Used during coercion of types and relationship handling, dates are considered valid
|
||||
* and can be used as a display field, but objects and arrays cannot.
|
||||
* @param test
|
||||
*/
|
||||
export function getPrimaryDisplay(test: any): string | undefined {
|
||||
if (test instanceof Date) {
|
||||
return test.toISOString()
|
||||
}
|
||||
if (Array.isArray(test) && test[0] && typeof test[0] !== "object") {
|
||||
return test.join(", ")
|
||||
}
|
||||
if (typeof test === "object") {
|
||||
return undefined
|
||||
}
|
||||
return test as string
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue