From 7ebe599389e895ab76c72445cda6008305483015 Mon Sep 17 00:00:00 2001 From: Stephanie Hingtgen Date: Mon, 27 Jan 2025 11:35:30 -0700 Subject: [PATCH] Library elements: do not error if dashboard is not found (#99608) --- pkg/services/libraryelements/database.go | 3 +++ pkg/services/libraryelements/libraryelements_test.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/pkg/services/libraryelements/database.go b/pkg/services/libraryelements/database.go index e07f3a08470..c68ee55c2a1 100644 --- a/pkg/services/libraryelements/database.go +++ b/pkg/services/libraryelements/database.go @@ -722,6 +722,9 @@ func (l *LibraryElementService) getConnections(c context.Context, signedInUser i } ds, err := l.dashboardsService.GetDashboardUIDByID(c, &dashboards.GetDashboardRefByIDQuery{ID: connection.ConnectionID}) if err != nil { + if errors.Is(err, dashboards.ErrDashboardNotFound) { + continue + } return err } connections = append(connections, model.LibraryElementConnectionDTO{ diff --git a/pkg/services/libraryelements/libraryelements_test.go b/pkg/services/libraryelements/libraryelements_test.go index ef2876736d9..fd7bb559a12 100644 --- a/pkg/services/libraryelements/libraryelements_test.go +++ b/pkg/services/libraryelements/libraryelements_test.go @@ -166,6 +166,10 @@ func TestGetLibraryPanelConnections(t *testing.T) { err := sc.service.ConnectElementsToDashboard(sc.reqContext.Req.Context(), sc.reqContext.SignedInUser, []string{sc.initialResult.Result.UID}, dashInDB.ID) require.NoError(t, err) + // add a connection where the dashboard doesn't exist. Shouldn't be returned in the list + err = sc.service.ConnectElementsToDashboard(sc.reqContext.Req.Context(), sc.reqContext.SignedInUser, []string{sc.initialResult.Result.UID}, 99999999) + require.NoError(t, err) + var expected = func(res model.LibraryElementConnectionsResponse) model.LibraryElementConnectionsResponse { return model.LibraryElementConnectionsResponse{ Result: []model.LibraryElementConnectionDTO{