-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Printing a proto breaks equality #1339
Comments
This is known behavior, and is intended. Protobufs have a bit of bookkeeping information that assists in keeping track of various things, for instance, unknown fields, a size cache, and some MessageSet state. You need to check for equality based on semantics, not on a pure reflection comparison. There is a generic |
Thanks this makes sense. Unfortunately test helpers like mockgen use reflect.DeepEqual. It would be nice if reflect.DeepEqual can fall back to generic proto.Equal for proto struct. |
@puellanivis @viswesh-swaminathan Are you also aware about how printing is just changing this bookkeeping information due to which reflect.DeepEqual is failing? I ran into similar issue, where I also observed printing both proto messages once will make them equal forever after that. I went to String() method of structpb.Value, but couldn't find anything where we are changing original message. |
printing purposefully adds randomness |
I'm afraid |
What version of protobuf and what language are you using?
Version v1.5.2
What did you do?
https://play.golang.org/p/ZwLkLcH7Ci_w
What did you expect to see?
Protos should be still be equal after printing.
What did you see instead?
Protos are not equal after calling String().
Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).
Anything else we should know about your project / environment?
The text was updated successfully, but these errors were encountered: