SQL Datasources: Fix variable throwing error if query returns no data (#65937)

* Fix SQL query variable throwing error if query returns no data

* Tests to verify that metricFindQuery returns properly and doesn't throw error

* Fix all codepaths that might throw errors because of undefined backendSrv response
This commit is contained in:
Victor Marin
2023-04-11 15:54:55 +03:00
committed by GitHub
parent 0aa301e251
commit 02a8bc76d2
6 changed files with 443 additions and 22 deletions

View File

@@ -164,7 +164,7 @@ export abstract class SqlDatasource extends DataSourceWithBackend<SQLQuery, SQLO
.pipe(
map((res: FetchResponse<BackendDataSourceResponse>) => {
const rsp = toDataQueryResponse(res, queries);
return rsp.data[0];
return rsp.data[0] ?? { fields: [] };
})
)
);