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

Preserve unknown fields when converting between FileDescriptorProto and ImageFile #1855

Conversation

jhump
Copy link
Member

@jhump jhump commented Feb 22, 2023

This way, if a field is ever added to the descriptors and then serialized by a newer version of buf, an older version of buf won't mangle it and inadvertently drop those newer fields.

The place in protodescriptor is the code path used for converting an image file to a descriptor proto. And the place in bufimage is for the other direction.

@jhump jhump requested a review from bufdev February 22, 2023 23:00
@@ -455,22 +455,19 @@ func TestBasic(t *testing.T) {
)
diff := cmp.Diff(protoImage, bufimage.ImageToProtoImage(newImage), protocmp.Transform())
require.Equal(t, "", diff)
// TODO: all of the below proto equality checks should use cmp.Diff
Copy link
Member Author

@jhump jhump Feb 22, 2023

Choose a reason for hiding this comment

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

I had to address this TODO because now that the ProtoReflect method might be called (to query/set unknown fields), the internal, unexported atomicMessageState pointer field of the message can differ between the two messages being compared (previously, by coincidence, was always nil on both sides).

private/bufpkg/bufimage/util.go Outdated Show resolved Hide resolved
Copy link
Member

@bufdev bufdev left a comment

Choose a reason for hiding this comment

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

approved pending two comments (will likely have to approve again to allow github to merge)

private/bufpkg/bufimage/util.go Outdated Show resolved Hide resolved
private/bufpkg/bufimage/util.go Outdated Show resolved Hide resolved
@jhump jhump merged commit 83ee368 into main Feb 23, 2023
@jhump jhump deleted the jh/preserve-unknown-fields-when-converting-between-filedescriptorproto-and-imagefile branch February 23, 2023 16:45
twoism pushed a commit that referenced this pull request Mar 2, 2023
… and `ImageFile` (#1855)

This way, if a field is ever added to the descriptors and then
serialized by a newer version of `buf`, an older version of `buf` won't
mangle it and inadvertently drop those newer fields.
Monirul1 pushed a commit to Monirul1/buf that referenced this pull request Apr 30, 2023
… and `ImageFile` (bufbuild#1855)

This way, if a field is ever added to the descriptors and then
serialized by a newer version of `buf`, an older version of `buf` won't
mangle it and inadvertently drop those newer fields.
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

Successfully merging this pull request may close these issues.

2 participants