grpc-ecosystem/grpc-gateway
View on GitHubInconsistency in handling null in message vs map<string, message> in PATCH parsing
Open
#2,056 opened on Mar 25, 2021
bughelp wanted
Description
๐ Bug Report
Null value is accepted for message-type field but not for same type map field.
To Reproduce
syntax = "proto3";
...
service SomeService {
rpc UpdateData(UpdateDataRequest) returns (Data) {
option (google.api.http).patch = "/";
option (google.api.http).body = "data";
}
}
message UpdateDataRequest {
Data data = 1;
google.protobuf.FieldMask update_mask = 2;
}
message Data {
google.protobuf.Duration wkt = 1;
Duration dur = 2;
map<string, google.protobuf.Duration> mapwkt = 3;
map<string, Duration> mapdur = 4;
}
message Duration { ... same as google.protobuf.Duration ... }
Expected behavior
I expect ability to send same value no matter is it a message-type field or map-of-messages-type field.
Actual Behavior
The problem is difference between 1 vs 5, and 3 vs 7 - I think null values should be either accepted or rejected in all cases.
{"wkt":null}โupdate_mask:{paths:"wkt"}{"wkt":"0s"}โupdate_mask:{paths:"wkt"} data:{wkt:{}}{"dur":null}โupdate_mask:{paths:"dur"}{"dur":{}}โupdate_mask:{} data:{dur:{}}{"mapwkt":{"key":null}}โ ERROR: unexpected token null{"mapwkt":{"key":"0s"}}โupdate_mask:{paths:"mapwkt"} data:{mapwkt:{key:"key" value:{}}}{"mapdur":{"key":null}}โ ERROR: unexpected token null{"mapdur":{"key":{}}}โupdate_mask:{paths:"mapdur"} data:{mapdur:{key:"key" value:{}}}
Also 3 vs 4 looks a bit weird, not sure is it correct or not and if not is it related to the issue.
Your Environment
Linux, go1.16.2, grpc-gateway v2.3.0.