From 86c105e1c8983b732f9bef6c90e88b47ddcbc994 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 16 Oct 2024 12:20:41 +0100 Subject: [PATCH] Ensure external tables always have a sourceId. --- packages/server/src/api/controllers/row/ExternalRequest.ts | 4 ++-- packages/server/src/sdk/app/tables/getters.ts | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/server/src/api/controllers/row/ExternalRequest.ts b/packages/server/src/api/controllers/row/ExternalRequest.ts index 56522acb33..9e68845a45 100644 --- a/packages/server/src/api/controllers/row/ExternalRequest.ts +++ b/packages/server/src/api/controllers/row/ExternalRequest.ts @@ -173,9 +173,9 @@ export class ExternalRequest { if (!opts.datasource) { if (sdk.views.isView(source)) { const table = await sdk.views.getTable(source.id) - opts.datasource = await sdk.datasources.get(table.sourceId!) + opts.datasource = await sdk.datasources.get(table.sourceId) } else { - opts.datasource = await sdk.datasources.get(source.sourceId!) + opts.datasource = await sdk.datasources.get(source.sourceId) } } diff --git a/packages/server/src/sdk/app/tables/getters.ts b/packages/server/src/sdk/app/tables/getters.ts index 280fb5378a..49944bce85 100644 --- a/packages/server/src/sdk/app/tables/getters.ts +++ b/packages/server/src/sdk/app/tables/getters.ts @@ -90,7 +90,11 @@ export async function getExternalTable( if (!entities[tableName]) { throw new Error(`Unable to find table named "${tableName}"`) } - return processTable(entities[tableName]) + const table = await processTable(entities[tableName]) + if (!table.sourceId) { + table.sourceId = datasourceId + } + return table } export async function getTable(tableId: string): Promise {