TemplateVariables: Fix custom variable function support (#62509)

Validate query values
This commit is contained in:
Andreas Christou 2023-01-30 17:49:16 +00:00 committed by GitHub
parent f23be415c5
commit 3ac97dd396
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,6 +24,7 @@ import {
import { toDataQueryError } from '@grafana/runtime'; import { toDataQueryError } from '@grafana/runtime';
import { isExpressionReference } from '@grafana/runtime/src/utils/DataSourceWithBackend'; import { isExpressionReference } from '@grafana/runtime/src/utils/DataSourceWithBackend';
import { backendSrv } from 'app/core/services/backend_srv'; import { backendSrv } from 'app/core/services/backend_srv';
import { queryIsEmpty } from 'app/core/utils/query';
import { dataSource as expressionDatasource } from 'app/features/expressions/ExpressionDatasource'; import { dataSource as expressionDatasource } from 'app/features/expressions/ExpressionDatasource';
import { ExpressionQuery } from 'app/features/expressions/types'; import { ExpressionQuery } from 'app/features/expressions/types';
@ -176,10 +177,14 @@ export function callQueryMethod(
queryFunction?: typeof datasource.query queryFunction?: typeof datasource.query
) { ) {
// If the datasource has defined a default query, make sure it's applied // If the datasource has defined a default query, make sure it's applied
request.targets = request.targets.map((t) => ({ request.targets = request.targets.map((t) =>
...datasource?.getDefaultQuery?.(CoreApp.PanelEditor), queryIsEmpty(t)
...t, ? {
})); ...datasource?.getDefaultQuery?.(CoreApp.PanelEditor),
...t,
}
: t
);
// If its a public datasource, just return the result. Expressions will be handled on the backend. // If its a public datasource, just return the result. Expressions will be handled on the backend.
if (datasource.type === 'public-ds') { if (datasource.type === 'public-ds') {