From 8bf2e642aa1df706b8a5c1d13c81538c38f0b5b9 Mon Sep 17 00:00:00 2001 From: gotjosh Date: Fri, 11 Feb 2022 09:13:51 -0700 Subject: [PATCH] Alerting: Fix updating notification channels in legacy (#45302) The problem here is that without the orgID we ignore the lookup of the existing notification channel just before updating and end up failing the update because there is no channel available. --- pkg/services/alerting/service.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/services/alerting/service.go b/pkg/services/alerting/service.go index 22d6bbaf121..5031b4cb9cc 100644 --- a/pkg/services/alerting/service.go +++ b/pkg/services/alerting/service.go @@ -2,6 +2,7 @@ package alerting import ( "context" + "fmt" "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/models" @@ -77,6 +78,7 @@ func (s *AlertNotificationService) UpdateAlertNotification(ctx context.Context, model := models.AlertNotification{ Id: cmd.Id, + OrgId: cmd.OrgId, Name: cmd.Name, Type: cmd.Type, Settings: cmd.Settings, @@ -137,7 +139,11 @@ func (s *AlertNotificationService) createNotifier(ctx context.Context, model *mo return nil, err } - if query.Result != nil && query.Result.SecureSettings != nil { + if query.Result == nil { + return nil, fmt.Errorf("unable to find the alert notification") + } + + if query.Result.SecureSettings != nil { var err error secureSettingsMap, err = s.EncryptionService.DecryptJsonData(ctx, query.Result.SecureSettings, setting.SecretKey) if err != nil {