1
0
Fork 0
mirror of synced 2024-07-09 00:06:05 +12:00

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:
mike12345567 2023-06-13 18:21:22 +01:00
parent 6158b4ac65
commit 68082eecf9
2 changed files with 24 additions and 1 deletions

View file

@ -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,

View file

@ -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
}