From 17ad44369cc9d969eb670d2ab796e202818e88fe Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 2 Feb 2021 10:35:00 +0000 Subject: [PATCH] Ensure fetching datasources always returns an array result --- packages/client/src/api/datasources.js | 7 +++---- packages/client/src/api/rows.js | 5 ++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/client/src/api/datasources.js b/packages/client/src/api/datasources.js index 7e5e11cd08..c2af90592e 100644 --- a/packages/client/src/api/datasources.js +++ b/packages/client/src/api/datasources.js @@ -3,7 +3,6 @@ import { fetchTableData } from "./tables" import { fetchViewData } from "./views" import { fetchRelationshipData } from "./relationships" import { executeQuery } from "./queries" -import { enrichRows } from "./rows" /** * Fetches all rows for a particular Budibase data source. @@ -28,7 +27,7 @@ export const fetchDatasource = async datasource => { parameters[param.name] = param.default } } - return await executeQuery({ queryId: datasource._id, parameters }) + rows = await executeQuery({ queryId: datasource._id, parameters }) } else if (type === "link") { rows = await fetchRelationshipData({ rowId: datasource.rowId, @@ -37,6 +36,6 @@ export const fetchDatasource = async datasource => { }) } - // Enrich rows so they can displayed properly - return await enrichRows(rows, tableId) + // Enrich the result is always an array + return Array.isArray(rows) ? rows : [] } diff --git a/packages/client/src/api/rows.js b/packages/client/src/api/rows.js index 3ebc191ff6..6930105d78 100644 --- a/packages/client/src/api/rows.js +++ b/packages/client/src/api/rows.js @@ -75,7 +75,10 @@ export const deleteRows = async ({ tableId, rows }) => { * be properly displayed. */ export const enrichRows = async (rows, tableId) => { - if (rows && rows.length && tableId) { + if (!Array.isArray(rows)) { + return [] + } + if (rows.length && tableId) { // Fetch table schema so we can check column types const tableDefinition = await fetchTableDefinition(tableId) const schema = tableDefinition && tableDefinition.schema