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

FieldMask path to oneof block does not validate #1344

Closed
mattnathan opened this issue Jul 22, 2021 · 2 comments
Closed

FieldMask path to oneof block does not validate #1344

mattnathan opened this issue Jul 22, 2021 · 2 comments

Comments

@mattnathan
Copy link

mattnathan commented Jul 22, 2021

What version of protobuf and what language are you using?
Version:

github.com/golang/protobuf v1.5.2
libprotoc 3.15.8
protoc-gen-go v1.26.0

What did you do?

Given a proto like

message Msg {
  oneof strings {
    string s1 = 1;
    string s2 = 2;
  }
}

After compiling into Go I ran

var Msg *myproto.Msg
mask, err := fieldmaskpb.New(Msg, "strings")
if err != nil {
  panic(err)
}
fmt.Println("Success")

What did you expect to see?

Success

I'd expect to be able to define a field mask for all options in a oneof block.

What did you see instead?

panic: proto: invalid path "strings" for message "myproto.Msg"

Anything else we should know about your project / environment?

I totally get that I could pass fieldmaskpb.New(Msg, "s1", "s2") but this result surprised me and quick Googling didn't show any related results so I thought I'd raise it here.

@neild
Copy link
Contributor

neild commented Jul 22, 2021

Field masks treat fields in oneofs as regular fields. For your example message, the possible paths are "s1" or "s2". See the documentation section "Field Masks and Oneof Fields":
https://pkg.go.dev/google.golang.org/protobuf/types/known/fieldmaskpb#FieldMask

Note that field masks are not Go specific; the Go implementation does not have any control over their specification.

@mattnathan
Copy link
Author

I have no idea why I missed those docs. I guess this can be closed then, was still a little surprised but I guess that's what the specification says.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants