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

status: Fix status incompatibility introduced by #6919 and move non-regeneratable proto code into /testdata #7724

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

arjan-bal
Copy link
Contributor

@arjan-bal arjan-bal commented Oct 10, 2024

Fixes: #7679

Problem

#6919 migrated usages of github.com/golang/protobuf to google.golang.org/protobuf/proto within status package. Prior to this, status.Details() called ptypes.UnmarshalAny which called proto.MessageV1(mt.New().Interface()) which called protoimpl.X.ProtoMessageV1Of(m) so the returned type always implemented protoadapt.MessageV1 and was always the same type given to status.WithDetails(). After the change, Status.Details() used anpb.Any.UnmarshallNew() which returns the vanilla type used while creating the anypb.Any which is only guaranteed to implement the MessageV2 API.

Effect

Users of code generated from protoc-gen-go < v1.4 (launched in 2020) would get a wrapped MessageV2 when calling Status.Details() even though they would have provided a type that only implemented MessageV1 to Status.WithDetails().

Fix

This PR brings back the call to protoimpl.X.ProtoMessageV1Of(m) by calling protoadapt.MessageV1Of before returning the Detail messages. A test is also added to catch regressions. Since the test uses generated code from protoc-gen-go v1.3, a dependency on github.com/golang/protobuf is re-introduced in go.mod.

Additional Changes

This PR also moves the generated code that is used for testing and must not be re-generated from the reflections/test module into a common directory under the parent grpc module.

RELEASE NOTES:

Copy link

codecov bot commented Oct 10, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 16 lines in your changes missing coverage. Please review.

Project coverage is 81.57%. Comparing base (5f178a8) to head (a0c3b84).
Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
...a/grpc_testing_not_regenerate/simple_message_v1.go 30.43% 16 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7724      +/-   ##
==========================================
- Coverage   81.77%   81.57%   -0.21%     
==========================================
  Files         361      364       +3     
  Lines       27826    28304     +478     
==========================================
+ Hits        22756    23088     +332     
- Misses       3865     4023     +158     
+ Partials     1205     1193      -12     
Files with missing lines Coverage Δ
internal/status/status.go 89.87% <100.00%> (ø)
testdata/grpc_testing_not_regenerate/testv3.go 6.70% <ø> (ø)
...a/grpc_testing_not_regenerate/simple_message_v1.go 30.43% <30.43%> (ø)

... and 26 files with indirect coverage changes

}

if diff := cmp.Diff(details, gotDetails, protocmp.Transform()); diff != "" {
t.Errorf("(%v).Details got unexpected output, diff (-got +want):\n%s", s, diff)
Copy link
Contributor

Choose a reason for hiding this comment

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

The order in the output, (-got +want), needs to be swapped I guess based on the order of parameters passed to cmp.Diff.

Comment on lines +213 to +218
details := []protoadapt.MessageV1{
&tpb.SimpleMessage{
Data: "abc",
},
&testpb.Empty{},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nit (optional)

I feel this is more readable and compact:

	details := []protoadapt.MessageV1{
		&tpb.SimpleMessage{Data: "abc"},
		&testpb.Empty{},
	}

@@ -0,0 +1,27 @@
/*
* Copyright 2022 gRPC authors.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be 2024?

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

Successfully merging this pull request may close these issues.

status/Details: unexpected code breaks after upgrading to v1.62.0 and higher
3 participants