{"record":{"id":"b9472e93586ca0a5","repo":"grafana/grafana","slug":"datasource-describeref-ref-was-not-found","errorCode":null,"errorMessage":"Datasource ${describeRef(ref)} was not found","messagePattern":"Datasource (.+?) was not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/grafana-runtime/src/services/dataSource/dataSource.ts","lineNumber":53,"sourceCode":" */\nexport async function getDataSourceInstance(\n  ref?: DataSourceRef | string | null,\n  scopedVars?: ScopedVars\n): Promise<DataSourceApi> {\n  if (isExpressionReference(ref)) {\n    const expressionDs = getExpressionDataSourceInstance();\n    if (!expressionDs) {\n      throw new Error(\n        'Expression datasource has not been initialised. Call setExpressionDataSourceInstance during application boot.'\n      );\n    }\n    return expressionDs;\n  }\n\n  try {\n    let settings = await getDataSourceInstanceSettings(ref, scopedVars);\n    if (!settings) {\n      throw new Error(`Datasource ${describeRef(ref)} was not found`);\n    }\n\n    // When ref is a template variable, the settings keep the variable string in uid/name\n    // (e.g. \"${datasource}\") with the resolved uid in rawRef — correct for the settings API,\n    // but a plugin instance built from them would carry the variable as its identity. Legacy\n    // DatasourceSrv.get() interpolates and returns the concrete instance, so re-resolve\n    // through rawRef and construct/cache from the concrete settings.\n    if (settings.rawRef && settings.rawRef.uid !== settings.uid) {\n      settings = await getDataSourceInstanceSettings(settings.rawRef);\n      if (!settings) {\n        throw new Error(`Datasource ${describeRef(ref)} was not found`);\n      }\n    }\n\n    const cacheUid = settings.uid;\n\n    const cached = getCachedPlugin(cacheUid);\n    if (cached) {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/grafana/grafana/blob/ae3104e3690e28e72c8f0c97efc12647a70f75c3/packages/grafana-runtime/src/services/dataSource/dataSource.ts#L35-L71","documentation":"getDataSourceInstance(ref) resolves a data source by uid/name/DataSourceRef with optional template scopedVars. It first calls getDataSourceInstanceSettings(ref, scopedVars); if that returns null/undefined (no matching datasource in the registry/config), it throws 'Datasource <ref> was not found'. describeRef renders the ref (uid or name) into the message.","triggerScenarios":"Calling getDataSourceInstance({ uid: 'nonexistent-uid' }); a dashboard JSON referencing a datasource uid that does not exist in this Grafana instance; a template variable resolving to an empty or missing datasource.","commonSituations":"Importing a dashboard from another Grafana whose datasource uids do not exist locally; deleting a datasource still referenced by panels/alerts; stale or typo'd uid in provisioning; permission/RBAC changes hiding the datasource from the current user.","solutions":["Verify the uid/name exists via getDataSourceInstanceSettings(ref) or the Data Sources UI.","When importing dashboards, remap datasource refs through the import dialog or update the JSON.","Ensure template variables resolve to a real datasource the user can access.","Re-provision or recreate the deleted datasource with the same uid."],"exampleFix":"// before\nconst ds = await getDataSourceInstance({ uid: savedPanel.datasourceUid });\n\n// after: guard before use\nconst settings = await getDataSourceInstanceSettings({ uid: savedPanel.datasourceUid });\nif (!settings) { handleMissingDatasource(savedPanel.datasourceUid); return; }\nconst ds = await getDataSourceInstance({ uid: settings.uid });","handlingStrategy":"validation","validationCode":"import { getDataSourceInstanceSettings, type DataSourceRef } from '@grafana/runtime';\n\nasync function datasourceExists(ref: DataSourceRef | string): Promise<boolean> {\n  return Boolean(await getDataSourceInstanceSettings(ref));\n}","typeGuard":null,"tryCatchPattern":"try {\n  const ds = await getDataSourceInstance(ref);\n} catch (e) {\n  if (/Datasource .* was not found/.test((e as Error).message)) {\n    showDatasourcePicker(ref);\n  } else throw e;\n}","preventionTips":["Resolve and validate datasource refs before issuing queries.","Use stable uids across environments or remap on dashboard import.","Surface a datasource picker instead of throwing when a ref is missing in user-facing flows."],"tags":["datasource","runtime","not-found","configuration"],"backgroundTag":null,"analyzedSha":"ae3104e3690e28e72c8f0c97efc12647a70f75c3","analyzedAt":"2026-08-12T12:48:38.752Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}