{"record":{"id":"194081298c72a2f9","repo":"Budibase/budibase","slug":"no-datasource-provided-for-external-query","errorCode":null,"errorMessage":"No datasource provided for external query","messagePattern":"No datasource provided for external query","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/server/src/integrations/base/query.ts","lineNumber":27,"sourceCode":"\nfunction isEnriched(\n  json: QueryJson | EnrichedQueryJson\n): json is EnrichedQueryJson {\n  return \"datasource\" in json\n}\n\nexport async function makeExternalQuery(\n  json: QueryJson | EnrichedQueryJson\n): Promise<DatasourcePlusQueryResponse> {\n  if (!isEnriched(json)) {\n    json = await enrichQueryJson(json)\n    if (json.datasource) {\n      json.datasource = await sdk.datasources.enrich(json.datasource)\n    }\n  }\n\n  if (!json.datasource) {\n    throw new Error(\"No datasource provided for external query\")\n  }\n\n  const Integration = await getIntegration(json.datasource.source)\n\n  if (!isDatasourcePlusConstructor(Integration)) {\n    throw \"Datasource does not support query.\"\n  }\n\n  const integration = new Integration(json.datasource.config)\n  return integration.query(json)\n}\n","sourceCodeStart":9,"sourceCodeEnd":39,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/integrations/base/query.ts#L9-L39","documentation":"makeExternalQuery is the core execution path for all SQL/REST integrations in Budibase. Before dispatching a request it enriches and validates the datasource object on the incoming JSON request; if json.datasource is absent or falsy there is no connection to run against, so it throws immediately. This is a programming/configuration bug on the caller's side, not a transient network issue.","triggerScenarios":"Calling makeExternalQuery (directly or via makeTableRequest, response, run, handleManyRelationships, or the relationship-removal helpers) with a JSON body whose `datasource` property is undefined, null, or was not populated by the caller — e.g. building the request object manually or a datasource fetch returned nothing.","commonSituations":"Custom scripts or automations constructing external query payloads by hand; an enrich step silently clearing a malformed datasource; API clients calling internal server endpoints without embedding the datasource entity; passing a datasource-less pagination/page request.","solutions":["Ensure the request payload includes a complete datasource object with at least `_id` and `source` populated before calling makeExternalQuery","Fetch the datasource entity from the DB first (e.g. sdk.datasources.get(datasourceId)) and attach it to json.datasource","If json.datasource should already exist, check the code path that builds the request (makeTableRequest / relationship helpers) for a variable holding the datasource that is undefined","Run the enrich step unconditionally: only skip it when datasource truly won't be needed"],"exampleFix":"// before\nawait makeExternalQuery(ctx, { operation: Operation.READ, table: table })\n// after\nconst datasource = await sdk.datasources.get(table.datasourceId)\nawait makeExternalQuery(ctx, { datasource, operation: Operation.READ, table: table })","handlingStrategy":"validation","validationCode":"function assertDatasource(json) {\n  if (!json || !json.datasource || !json.datasource.source) {\n    throw new Error('External query requires a datasource with a source')\n  }\n}\n// call before makeExternalQuery(json)","typeGuard":"function hasDatasource(json) {\n  return typeof json === 'object' && json !== null &&\n    'datasource' in json && json.datasource != null &&\n    typeof json.datasource.source === 'string'\n}","tryCatchPattern":"try {\n  await makeExternalQuery(ctx, json)\n} catch (err) {\n  if (err.message === 'No datasource provided for external query') {\n    // fix payload: fetch + attach datasource, or surface a 400 to the caller\n  } else throw err\n}","preventionTips":["Always resolve the datasource entity before building query payloads","Validate request bodies server-side before dispatching to integrations","Add a unit test asserting query builders always include datasource"],"tags":["datasource","configuration","budibase"],"backgroundTag":"missing-required-config","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}