From 9f9f8c3a23333cd0346df1b973c9920d6d4d3b7c Mon Sep 17 00:00:00 2001 From: Joao Silva <100691367+JoaoSilvaGrafana@users.noreply.github.com> Date: Thu, 26 May 2022 14:31:33 +0100 Subject: [PATCH] Variables: Fixes issue with data source variables not being correctly used in panel queries (#49323) (#49697) --- public/app/features/query/state/PanelQueryRunner.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/public/app/features/query/state/PanelQueryRunner.ts b/public/app/features/query/state/PanelQueryRunner.ts index f7ceea18895..dcd7ef65c2a 100644 --- a/public/app/features/query/state/PanelQueryRunner.ts +++ b/public/app/features/query/state/PanelQueryRunner.ts @@ -236,9 +236,11 @@ export class PanelQueryRunner { try { const ds = await getDataSource(datasource, request.scopedVars); - // Attach the data source name to each query + // Attach the data source to each query request.targets = request.targets.map((query) => { - if (!query.datasource) { + // When using a data source variable, the panel might have the incorrect datasource + // stored, so when running the query make sure it is done with the correct one + if (!query.datasource || (query.datasource.uid !== ds.uid && !ds.meta.mixed)) { query.datasource = ds.getRef(); } return query;