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: patch request body parsing for model metadata [DET-3939] #1144

Merged
merged 4 commits into from
Aug 20, 2020
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
4 changes: 2 additions & 2 deletions common/determined_common/experimental/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def add_metadata(self, metadata: Dict[str, Any]) -> None:
api.patch(
self._master,
"/api/v1/models/{}".format(self.name),
body={"model": {"metadata": self.metadata}},
body={"model": {"metadata": self.metadata, "description": self.description}},
)

def remove_metadata(self, keys: List[str]) -> None:
Expand All @@ -194,7 +194,7 @@ def remove_metadata(self, keys: List[str]) -> None:
api.patch(
self._master,
"/api/v1/models/{}".format(self.name),
body={"model": {"metadata": self.metadata}},
body={"model": {"metadata": self.metadata, "description": self.description}},
)

def to_json(self) -> Dict[str, Any]:
Expand Down
15 changes: 2 additions & 13 deletions master/internal/api_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,8 @@ func (a *apiServer) PatchModel(
return nil, err
}

paths := req.UpdateMask.GetPaths()
for _, path := range paths {
switch {
case path == "model.description":
getResp.Model.Description = req.Model.Description
case strings.HasPrefix(path, "model.metadata"):
getResp.Model.Metadata = req.Model.Metadata
case !strings.HasPrefix(path, "update_mask"):
return nil, status.Errorf(
codes.InvalidArgument,
"only description and metadata fields are mutable. cannot update %s", path)
}
}
getResp.Model.Description = req.Model.Description
getResp.Model.Metadata = req.Model.Metadata

b, err := protojson.Marshal(getResp.Model.Metadata)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion proto/scripts/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def clean(fn: str) -> None:
paths[key.replace(".", "_")] = value
spec["paths"] = paths

del spec["definitions"]["protobufFieldMask"]
for key, value in spec["definitions"].items():
# Remove definitions that should be hidden from the user.
if key == "protobufAny":
Expand Down
2 changes: 1 addition & 1 deletion proto/src/determined/api/v1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ service Determined {
}
// Update model fields
rpc PatchModel(PatchModelRequest) returns (PatchModelResponse) {
option (google.api.http) = {patch: "/api/v1/models/{model.name}" body: "model"};
option (google.api.http) = {patch: "/api/v1/models/{model.name}" body: "*"};
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {tags: "Models"};
}
// Get a list of models.
Expand Down
4 changes: 0 additions & 4 deletions proto/src/determined/api/v1/model.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ syntax = "proto3";
package determined.api.v1;
option go_package = "github.com/determined-ai/determined/proto/pkg/apiv1";

import "google/protobuf/field_mask.proto";

import "determined/api/v1/pagination.proto";
import "determined/model/v1/model.proto";

Expand Down Expand Up @@ -77,8 +75,6 @@ message PostModelResponse {
message PatchModelRequest {
// The model desired model fields and values.
determined.model.v1.Model model = 1;
// An update mask for the above model.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we remove the fieldmask import as well

google.protobuf.FieldMask update_mask = 2;
}

// Response to PatchModelRequest.
Expand Down