-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
runtime: support FieldMask as query param #529
runtime: support FieldMask as query param #529
Conversation
Can you add a test to verify this functionality? I'd be very happy to merge once that happens. Thanks! |
Yeah, will do!
…On Sun, 21 Jan 2018 at 04:56, Andrew Z Allen ***@***.***> wrote:
Can you add a test to verify this functionality? I'd be very happy to
merge once that happens. Thanks!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#529 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACIPlgK7bkV_RT-dop_ySAt2MrwAJgi3ks5tMrVfgaJpZM4Rix5->
.
|
ready to review @achew22! |
I love being reviewed! On a more serious note. LGTM, let's ship it. Thanks for contributing! |
Haha, thanks!
…On Sun, 21 Jan 2018 at 12:36, Andrew Z Allen ***@***.***> wrote:
Merged #529 <#529>.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#529 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACIPlv_afB9Hc-1Z6N8vPx9HhA_1-fXcks5tMyFJgaJpZM4Rix5->
.
|
I've tried playing around with this a bit, and I can't seem to get this to work the way I think it should work. Given the example and the code in this PR, I'm assuming the field mask should be provided as a query parameter like so: curl -k -X PATCH "https://localhost:11000/api/v1/user/1?update_mask=role" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"role\": \"ADMIN\"}" Given the following definitions: rpc UpdateUser(UpdateUserRequest) returns (User) {
option (google.api.http) = {
patch: "/api/v1/user/{user.id}"
body: "user"
};
}
message UpdateUserRequest {
User user = 1;
google.protobuf.FieldMask update_mask = 2;
} Unfortunately, this kind of definition doesn't even survive generation; the generated code tries to decode into a if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.User); err != nil { Is there an example of this implemented a used successfully in the wild? The query test "example" is basically useless as far as I'm concerned. |
I've tested with this proto:
And this worked:
Where
So i firmly believe that something is not working on your side. Are you using the standard go generator or something like gogo? Give us a full example and perhaps we can go further. |
@glerchundi thanks for that, sounds like my use case should work, I will do some more testing and report back. |
Update: my initial problems were indeed because I was using GoGo Protobuf. My intentions are actually to investigate whether this works with gogoprotobuf, but I wanted to get it working first, so thanks for pointing me in the right direction. I will see what would need to be done on the gogo/protobuf side, but I expect this will flat out not work with gogo/protobuf until an alternative implementation for Line 275 in 58f78b9
Out of interest; since the update_mask specifies fields as strings, what reflect magic do you use to figure out which fields of the struct to update? |
Good investigation.
But I don't know why it's not working, official: https://github.com/google/go-genproto/blob/master/protobuf/field_mask/field_mask.pb.go#L249 Also the structs have the same parameters (just one) with the same signature which means the reflection should work as well. And
We're pre-generating everything, updateable fields which we then map to database fields, no reflection magic at all. With something like this:
Would be interesting to see your progress. |
@glerchundi I'm afraid you're making an incorrect assumption about how If you want more information about this kind of thing, you're welcome to read my blogpost on There are basically two solutions to this problem:
Anyway, as I mentioned, there seems to be another problem here with the |
Right.
What about https://github.com/golang/protobuf/blob/master/proto/properties.go#L846-L855 |
Hm, that is a fair point, I didn't know about that method. It would solve the problem with |
Better than nothing. I think the problem of how to interoperate is much bigger than these concrete methods. I still think that in this case using interfaces is the way to go and would fix your current issue, what do you think if start by fixing this in |
I agree, and as I said there are other issues here with gogo/protobuf which I will investigate at the same time. Feel free to follow the discussion in gogo/grpc-example#9 if you wish. |
In order to support
FieldMask
in query params, as Google proposes, this should be treated as another known type./cc @achew22 @tmc
As a reference:
https://cloud.google.com/iam/reference/rest/v1/organizations.roles/patch
https://github.com/googleapis/googleapis/blob/f704d14a7224a140bca5cc26835fae471eaf7281/google/iam/admin/v1/iam.proto#L157
https://github.com/googleapis/googleapis/blob/f704d14a7224a140bca5cc26835fae471eaf7281/google/iam/admin/v1/iam.proto#L614-L626