fix: replace deprecated templateSrv.getAdhocFilters usage#129
Draft
samjewell wants to merge 4 commits into
Draft
fix: replace deprecated templateSrv.getAdhocFilters usage#129samjewell wants to merge 4 commits into
samjewell wants to merge 4 commits into
Conversation
Bundle Size ChangesHello! 👋 This comment was generated by a Github Action to help you and reviewers understand the impact of your PR on frontend bundle sizes. Whenever this PR is updated, this comment will update to reflect the latest changes.
View detailed bundle informationAdded No assets were added Removed No assets were removed Bigger No assets were bigger Smaller
View module informationAdded No modules were added Removed No modules were removed Bigger
Smaller No modules were smaller |
Use request-provided AdHoc filters in datasource template application and stop reading deprecated templateSrv.getAdhocFilters in runtime code paths to avoid Grafana deprecation warnings. Co-authored-by: Cursor <cursoragent@cursor.com>
55bb1a6 to
a3c8195
Compare
samjewell
commented
Feb 13, 2026
samjewell
left a comment
Collaborator
Author
There was a problem hiding this comment.
I've tested this locally, and it works fine ✅
Pass dashboard AdHoc filters from QueryEditor into buildCubeQueryJson so SQL preview reflects the same filter context as runtime queries. Update SQL preview tests to assert merged query and dashboard filter behavior. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Bugbot Autofix prepared fixes for 2 of the 2 bugs found in the latest run.
Or push these changes by commenting: Preview (1749ae53dc)diff --git a/src/components/QueryEditor.tsx b/src/components/QueryEditor.tsx
--- a/src/components/QueryEditor.tsx
+++ b/src/components/QueryEditor.tsx
@@ -19,10 +19,11 @@
datasource,
}: QueryEditorProps<DataSource, CubeQuery, CubeDataSourceOptions>) {
const styles = useStyles2(getStyles);
- const adHocFilters = useMemo(() => {
- return getTemplateSrv().getAdhocFilters(datasource.name) as NonNullable<Parameters<typeof buildCubeQueryJson>[2]>;
- }, [datasource.name]);
- const cubeQueryJson = useMemo(() => buildCubeQueryJson(query, datasource, adHocFilters), [query, datasource, adHocFilters]);
+ const cubeQueryJson = useMemo(() => {
+ const templateSrv = getTemplateSrv();
+ const adHocFilters = (templateSrv.getAdhocFilters?.(datasource.name) ?? []) as NonNullable<Parameters<typeof buildCubeQueryJson>[2]>;
+ return buildCubeQueryJson(query, datasource, adHocFilters);
+ }, [query, datasource]);
const { data, isLoading: metadataIsLoading, isError: metadataIsError } = useMetadataQuery({ datasource });
const metadata = data ?? { dimensions: [], measures: [] }; |
Restore prior SQL preview test names and compact assertions while preserving coverage for AdHoc filter inclusion and merged filter behavior. Co-authored-by: Cursor <cursoragent@cursor.com>
d2d1e20 to
0a54c69
Compare
Remove obsolete getAdhocFilters scaffolding and centralize the default templateSrv replace mock in applyTemplateVariables tests to reduce duplication. Co-authored-by: Cursor <cursoragent@cursor.com>
0a54c69 to
03db831
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

BLOCKED⚠️
See grafana/grafana#75552 (comment)
The SQL Preview can't show the
WHEREclauses any more 😢But I personally believe it's valuable to show these to our end users. Let's wait and see what Torkel and Dominik say.
Summary
templateSrv.getAdhocFiltersin datasource execution pathsapplyTemplateVariablesto consume request-provided AdHoc filters and keep operator mapping typed viaOperatorTest plan
npm run typechecknpm run test:ci -- src/datasource.test.tsnpm run test:ci -- src/components/QueryEditor.test.tsxNote
Medium Risk
Touches query construction and filter/operator mapping, so regressions could change what data is returned for dashboards using AdHoc filters or template variables.
Overview
Updates AdHoc filter handling to avoid deprecated
templateSrv.getAdhocFilters()in backend execution:DataSource.applyTemplateVariablesandbuildCubeQueryJsonnow accept request-provided AdHoc filters as an explicit argument and merge them into Cube filters.Tightens operator typing by returning
Operatorvalues frommapOperator, and updates unit tests to pass AdHoc filters directly intoapplyTemplateVariables(simplifying template service mocks) while keeping SQL preview query building aware of AdHoc filters.Written by Cursor Bugbot for commit 03db831. This will update automatically on new commits. Configure here.