DataSources: Fixes issue with expressions not being queried (#50446)

This commit is contained in:
Joao Silva 2022-06-09 12:50:16 +01:00 committed by GitHub
parent a263a0f9bd
commit ce1ee4de04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,6 +26,7 @@ import {
transformDataFrame, transformDataFrame,
} from '@grafana/data'; } from '@grafana/data';
import { getTemplateSrv } from '@grafana/runtime'; import { getTemplateSrv } from '@grafana/runtime';
import { ExpressionDatasourceRef } from '@grafana/runtime/src/utils/DataSourceWithBackend';
import { StreamingDataFrame } from 'app/features/live/data/StreamingDataFrame'; import { StreamingDataFrame } from 'app/features/live/data/StreamingDataFrame';
import { isStreamingDataFrame } from 'app/features/live/data/utils'; import { isStreamingDataFrame } from 'app/features/live/data/utils';
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
@ -235,12 +236,13 @@ export class PanelQueryRunner {
try { try {
const ds = await getDataSource(datasource, request.scopedVars); const ds = await getDataSource(datasource, request.scopedVars);
const isMixedDS = ds.meta?.mixed;
// Attach the data source to each query // Attach the data source to each query
request.targets = request.targets.map((query) => { request.targets = request.targets.map((query) => {
const isExpressionQuery = query.datasource?.type === ExpressionDatasourceRef.type;
// When using a data source variable, the panel might have the incorrect 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 // 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)) { if (!query.datasource || (query.datasource.uid !== ds.uid && !isMixedDS && !isExpressionQuery)) {
query.datasource = ds.getRef(); query.datasource = ds.getRef();
} }
return query; return query;