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