-
Notifications
You must be signed in to change notification settings - Fork 359
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: allow workspaces to be attempted to be deleted when experiments had existed historically [CM-412] #10050
base: main
Are you sure you want to change the base?
Changes from all commits
66df515
adcaa6b
eefdedf
fa9bcfa
a7e56d4
b859ee7
1f1b37f
b219f62
a9ac51c
3e8ad2e
fde6e4c
0808a9c
f741612
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -307,6 +307,17 @@ func (a *apiServer) workspaceHasModels(ctx context.Context, workspaceID int32) ( | |||||
return exists, nil | ||||||
} | ||||||
|
||||||
func (a *apiServer) workspaceHasExperiments(ctx context.Context, workspaceID int32) (bool, error) { | ||||||
exists, err := db.Bun().NewSelect().Table("experiments"). | ||||||
Join("INNER JOIN projects ON experiments.project_id = projects.id"). | ||||||
Where("projects.workspace_id=?", workspaceID). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Exists(ctx) | ||||||
if err != nil { | ||||||
return false, fmt.Errorf("checking workspace for experiments: %w", err) | ||||||
} | ||||||
return exists, nil | ||||||
} | ||||||
|
||||||
func (a *apiServer) GetWorkspace( | ||||||
ctx context.Context, req *apiv1.GetWorkspaceRequest, | ||||||
) (*apiv1.GetWorkspaceResponse, error) { | ||||||
|
@@ -1293,13 +1304,22 @@ func (a *apiServer) DeleteWorkspace( | |||||
return nil, err | ||||||
} | ||||||
|
||||||
modelsExist, err := a.workspaceHasModels(ctx, req.Id) | ||||||
maxrussell marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
if err != nil { | ||||||
return nil, err | ||||||
checks := []struct { | ||||||
checkFunc func(context.Context, int32) (bool, error) | ||||||
errorStr string | ||||||
}{ | ||||||
{a.workspaceHasModels, "workspace (%d) contains models; move or delete models first"}, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @maxrussell it looks like you took this over. can you unroll this loop? |
||||||
{a.workspaceHasExperiments, "workspace (%d) contains experiments; move or delete experiments first"}, | ||||||
} | ||||||
if modelsExist { | ||||||
return nil, status.Errorf(codes.FailedPrecondition, "workspace (%d) contains models; move or delete models first", | ||||||
req.Id) | ||||||
|
||||||
for _, check := range checks { | ||||||
exists, err := check.checkFunc(ctx, req.Id) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
if exists { | ||||||
return nil, status.Errorf(codes.FailedPrecondition, check.errorStr, req.Id) | ||||||
} | ||||||
} | ||||||
|
||||||
holder := &workspacev1.Workspace{} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
"fmt" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
@@ -939,7 +940,7 @@ func TestDeleteWorkspace(t *testing.T) { | |
mockRM := MockRM() | ||
noName := "" | ||
// set up api server | ||
api, _, ctx := setupAPITest(t, nil, mockRM) | ||
api, curUser, ctx := setupAPITest(t, nil, mockRM) | ||
api.m.allRms = map[string]rm.ResourceManager{noName: mockRM} | ||
// set up command service - required for successful DeleteWorkspaceRequest calls | ||
cs, err := command.NewService(api.m.db, api.m.rm) | ||
|
@@ -1002,6 +1003,44 @@ func TestDeleteWorkspace(t *testing.T) { | |
Id: resp.Workspace.Id, | ||
}) | ||
require.Error(t, err) | ||
|
||
// create another workspace, and add a experiment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, put the new test in a separate test. |
||
w, p := createProjectAndWorkspace(ctx, t, api) | ||
err = db.Bun().RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error { | ||
autoGeneratedNamespaceName, err := getAutoGeneratedNamespaceName(ctx, w, &tx) | ||
require.NoError(t, err) | ||
autoCreatedNamespace = autoGeneratedNamespaceName | ||
return nil | ||
}) | ||
require.NoError(t, err) | ||
e := createTestExpWithProjectID(t, api, curUser, p) | ||
_, err = db.Bun().NewUpdate().Table("experiments"). | ||
Set("state = ?", model.CompletedState). | ||
Where("id = ?", e.ID).Exec(ctx) | ||
require.NoError(t, err) | ||
_, err = api.DeleteWorkspace(ctx, &apiv1.DeleteWorkspaceRequest{ | ||
Id: int32(w), | ||
}) | ||
|
||
require.Error(t, err) | ||
// delete experiment, so that workspace can be deleted | ||
_, err = api.DeleteExperiment(ctx, &apiv1.DeleteExperimentRequest{ExperimentId: int32(e.ID)}) | ||
require.NoError(t, err) | ||
|
||
// since delete experiment is async, we need to wait for the experiment to be deleted | ||
for i := 0; i < 10; i++ { | ||
_, err = api.GetExperiment(ctx, &apiv1.GetExperimentRequest{ExperimentId: int32(e.ID)}) | ||
if err != nil { | ||
break | ||
} | ||
time.Sleep(1 * time.Second) | ||
} | ||
// delete the workspace successfully | ||
mockRM.On("DeleteNamespace", *autoCreatedNamespace).Return(nil).Once() | ||
_, err = api.DeleteWorkspace(ctx, &apiv1.DeleteWorkspaceRequest{ | ||
Id: int32(w), | ||
}) | ||
require.NoError(t, err) | ||
} | ||
|
||
func TestSetWorkspaceNamespaceBindings(t *testing.T) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
declare module 'moment' { | ||
import { Dayjs } from 'dayjs'; | ||
namespace moment { | ||
type Moment = Dayjs | ||
type Moment = Dayjs; | ||
} | ||
export = moment | ||
export as namespace moment | ||
export = moment; | ||
export as namespace moment; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
declare module 'notebook' { | ||
export default any; | ||
export default any; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's up with the sleeping? is this waiting on the deletes to finish? if so there's no way this doesn't flake eventually haha.