-
Notifications
You must be signed in to change notification settings - Fork 349
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
chore: cover and bunify project functions in postgres_experiments.go #8912
Conversation
✅ Deploy Preview for determined-ui canceled.
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8912 +/- ##
=======================================
Coverage 47.53% 47.54%
=======================================
Files 1066 1068 +2
Lines 170434 170513 +79
Branches 2235 2237 +2
=======================================
+ Hits 81015 81066 +51
- Misses 89261 89289 +28
Partials 158 158
Flags with carried forward coverage won't be shown. Click here to find out more.
|
} | ||
return &pID, nil | ||
} | ||
|
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.
moved function to postgres_project.go
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.
good catch
return 1, fmt.Errorf("given workspace or project is archived and cannot add new experiments") | ||
} | ||
return int(p.Id), nil | ||
} |
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.
moved function to postgres_projects.go
|
||
// user is logged in again during experiment creation, meaning args don't match | ||
mockUserArg := mock.MatchedBy(func(u model.User) bool { | ||
return u.ID == curUser.ID | ||
}) | ||
|
||
// Can't view forked experiment. |
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.
separated tests so they can be run individually
@@ -527,7 +527,7 @@ func (a *apiServer) deleteWorkspace( | |||
log.Debugf("deleting workspace %d projects", workspaceID) | |||
holder := &workspacev1.Workspace{} | |||
for _, pj := range projects { | |||
expList, err := a.m.db.ProjectExperiments(int(pj.Id)) | |||
expList, err := db.ProjectExperiments(context.TODO(), int(pj.Id)) |
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.
using context.TODO()
here because otherwise I was running into context cancelled errors; I think that defer rows.Close()
within ProjectExperiments(...)
might be cancelling the context
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.
LGTM; see nit/suggestion
} | ||
return &pID, nil | ||
} | ||
|
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.
good catch
func ProjectExperiments(ctx context.Context, pID int) (experiments []*model.Experiment, err error) { | ||
rows, err := Bun().NewSelect(). | ||
Model((*model.Experiment)(nil)). | ||
Column("experiment.id"). | ||
Column("state"). | ||
Column("config"). | ||
Column("start_time"). | ||
Column("end_time"). | ||
Column("archived"). | ||
Column("owner_id"). | ||
Column("notes"). | ||
Column("job_id"). | ||
Column("project_id"). | ||
Column("unmanaged"). | ||
ColumnExpr("u.username as username"). | ||
Join("JOIN users AS u ON (experiment.owner_id = u.id)"). | ||
Where("experiment.project_id = ?", pID). | ||
Rows(ctx) | ||
if err != nil { | ||
return nil, err | ||
return nil, fmt.Errorf("selecting project experiments: %w", err) | ||
} | ||
defer rows.Close() | ||
|
||
defer rows.Close() | ||
for rows.Next() { | ||
var exp model.Experiment | ||
if err = rows.StructScan(&exp); err != nil { | ||
return nil, errors.Wrap(err, "unable to read experiment from db") | ||
if err := Bun().ScanRow(ctx, rows, &exp); err != nil { | ||
return nil, fmt.Errorf("reading experiment from db: %w", err) | ||
} | ||
experiments = append(experiments, &exp) | ||
} | ||
|
||
if err := rows.Err(); err != nil { | ||
return nil, fmt.Errorf("selecting project experiments: %w", err) | ||
} |
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.
nit: could you follow the pattern of user.GetUserSetting here so you can avoid scanning rows & running defer rows.Close() to cancel the context?
something like:
exps := []*model.Experiment
err := db.Bun().NewSelect().Model(&exp)...Scan(ctx)
return exps, err
if you've already tried this, disregard -- but hopefully this allows you to pass in the ctx (and not context.TODO()) to these calls.
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.
Thank you for the suggestion! I'm not going to do this for performance reasons; but it's good to know about the tradeoffs / alternatives.
…8912) * initial commit to save progress * missed a file * remove duplicate func from workspace * fix formatting * fix bun query; do not redefine table nickname * fix git check issues * add clarity to error handling when workspace/project does not exist * remove unnecessary print statements * use new context for ProjectExperiments call * use fresh context for deleting projects, too
Description
RM-48 chore: cover and bunify project functions in postgres_experiments.go
Test Plan
ensure all unit/integration tests pass; there should be no change in behavior
ProjectExperiments
is called when deleting a workspace. Create a workspace, add a project, and an experiment. Then, delete it. It completes without error.Repeat above with deleting a project from a workspace.
Checklist
docs/release-notes/
.See Release Note for details.
Ticket
RM-48