From b57fe8e856a636d2f1ba3029cf7ee2a66bb6c4ab Mon Sep 17 00:00:00 2001 From: "grafana-delivery-bot[bot]" <132647405+grafana-delivery-bot[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 13:56:29 +0300 Subject: [PATCH] [v10.0.x] TemplateSrv: Fix ad hoc filters not applying correctly when using datasource variables (#76021) TemplateSrv: Fix ad hoc filters not applying correctly when using datasource variables (#75977) (cherry picked from commit 374e2a68f61ab1a41bac8cb459f6613187e04b55) Co-authored-by: kay delaney <45561153+kaydelaney@users.noreply.github.com> --- 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 413c2c11063..dbed9e3fe11 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 359a7c5af43..2980abfffef 100644 --- a/public/app/features/templating/template_srv.ts +++ b/public/app/features/templating/template_srv.ts @@ -125,7 +125,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); } }