From 374e2a68f61ab1a41bac8cb459f6613187e04b55 Mon Sep 17 00:00:00 2001 From: kay delaney <45561153+kaydelaney@users.noreply.github.com> Date: Thu, 5 Oct 2023 11:18:38 +0100 Subject: [PATCH] TemplateSrv: Fix ad hoc filters not applying correctly when using datasource variables (#75977) --- public/app/features/templating/template_srv.test.ts | 6 +++++- public/app/features/templating/template_srv.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/public/app/features/templating/template_srv.test.ts b/public/app/features/templating/template_srv.test.ts index 190bff5cce2..b822402f96e 100644 --- a/public/app/features/templating/template_srv.test.ts +++ b/public/app/features/templating/template_srv.test.ts @@ -198,7 +198,7 @@ describe('templateSrv', () => { { type: 'datasource', name: 'ds', - current: { value: 'logstash', text: 'logstash' }, + current: { value: 'logstash-id', text: 'logstash' }, }, { type: 'adhoc', name: 'test', datasource: { uid: 'oogle' }, filters: [1] }, { type: 'adhoc', name: 'test2', datasource: { uid: '$ds' }, filters: [2] }, @@ -209,6 +209,10 @@ describe('templateSrv', () => { name: 'oogle', uid: 'oogle', }), + logstash: mockDataSource({ + name: 'logstash', + uid: 'logstash-id', + }), }) ); }); diff --git a/public/app/features/templating/template_srv.ts b/public/app/features/templating/template_srv.ts index 7365efae0f7..ab4760f1c6a 100644 --- a/public/app/features/templating/template_srv.ts +++ b/public/app/features/templating/template_srv.ts @@ -142,7 +142,7 @@ export class TemplateSrv implements BaseTemplateSrv { if (variableUid === ds.uid) { filters = filters.concat(variable.filters); } else if (variableUid?.indexOf('$') === 0) { - if (this.replace(variableUid) === datasourceName) { + if (this.replace(variableUid) === ds.uid) { filters = filters.concat(variable.filters); } }