Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Treat trashed dashboard as deleted #4251

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dashboards/resource_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ func ResourceDashboard() common.Resource {
if err != nil {
return err
}

// Deletion of a dashboard moves it to the trash and subsequent reads still return the trashed dashboard.
// It cannot be updated unless it is untrashed, so we treat it as deleted to force recreation.
if resp.LifecycleState == dashboards.LifecycleStateTrashed {
d.SetId("")
return nil
}

d.Set("dashboard_change_detected", (resp.Etag != d.Get("etag").(string)))
return common.StructToData(resp, dashboardSchema, d)
},
Expand Down
17 changes: 17 additions & 0 deletions dashboards/resource_dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ func TestDashboardRead(t *testing.T) {
})
}

func TestDashboardReadTrashed(t *testing.T) {
qa.ResourceFixture{
MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) {
w.GetMockLakeviewAPI().EXPECT().Get(mock.Anything, dashboards.GetDashboardRequest{
DashboardId: "xyz",
}).Return(&dashboards.Dashboard{
DashboardId: "xyz",
LifecycleState: dashboards.LifecycleStateTrashed,
}, nil)
},
Resource: ResourceDashboard(),
Read: true,
Removed: true,
ID: "xyz",
}.ApplyNoError(t)
}

func TestDashboardUpdate(t *testing.T) {
qa.ResourceFixture{
MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) {
Expand Down
Loading