diff --git a/public/app/features/alerting/unified/components/rule-editor/QueryRows.tsx b/public/app/features/alerting/unified/components/rule-editor/QueryRows.tsx index 9db88e23170..d6d7a653dc4 100644 --- a/public/app/features/alerting/unified/components/rule-editor/QueryRows.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/QueryRows.tsx @@ -17,6 +17,7 @@ import { queriesWithUpdatedReferences } from './util'; import { Button, Card, Icon } from '@grafana/ui'; import { QueryOperationRow } from 'app/core/components/QueryOperationRow/QueryOperationRow'; import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; +import { omit } from 'lodash'; interface Props { // The query configuration @@ -108,19 +109,7 @@ export class QueryRows extends PureComponent { return item; } - const previous = getDataSourceSrv().getInstanceSettings(item.datasourceUid); - - if (previous?.type === settings.uid) { - return { - ...item, - datasourceUid: settings.uid, - }; - } - - return { - ...item, - datasourceUid: settings.uid, - }; + return copyModel(item, settings.uid); }); onQueriesChange(updatedQueries); }; @@ -291,6 +280,14 @@ export class QueryRows extends PureComponent { } } +function copyModel(item: AlertQuery, uid: string): Omit { + return { + ...item, + model: omit(item.model, 'datasource'), + datasourceUid: uid, + }; +} + interface DatasourceNotFoundProps { index: number; model: AlertDataQuery;