-
Notifications
You must be signed in to change notification settings - Fork 15.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
Fix nested Message objects in to_h #4962
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
CLA signed. |
CLAs look good, thanks! |
@oggy Does your code depends on the actual content of |
The current behavior is intentional, there is even a test for it: https://github.com/google/protobuf/blob/master/ruby/tests/basic.rb#L1026 What is the rationale for changing this? Is there prior art in Ruby that says this should be shallow instead of deep? |
Thanks for the quick responses! @TeBoring We do have code that uses @haberman Thanks for the test pointer. I would say there is prior art. Ruby's built-in
If deep |
@oggy Thanks for the explanation. I thought |
For example, for this proto file: ``` syntax = "proto3"; import "google/protobuf/struct.proto"; message Parent { map<string, Child> children = 1; } message Child { string name = 1; } ``` We used to have: ``` irb(main):001:0> Parent.new(children: {'a' => Child.new(name: 'a')}).to_h => {:children=>{"a"=>{:name=>"a"}}} ``` Now: ``` irb(main):001:0> Parent.new(children: {'a' => Child.new(name: 'a')}).to_h => {:children=>{"a"=><Child: name: "a">}} ``` It appears this changed in #2847/#396, but it's unclear what the intent was with these lines, so I'm assuming this was an unintended side-effect (it's not needed to solve #1761).
@TeBoring This is almost true. I've updated the test that @haberman mentioned. |
@oggy I like the idea of having a parameter to control whether it is deep or not. For the parameter default, I would be in favor of keeping it as it is, unless there is an argument that the shallow behavior is clearly better. I hear your point that we changed the behavior of this a year ago. But that was an intentional change that was a part of a bugfix. The current behavior has been in place for over a year now, so I don't think we should change it now unless it is obviously wrong. I hear your point about Struct. But to me a key difference is that Struct doesn't know when some of its members might also be Struct. Protobuf does know this. So the comparison doesn't seem exact. |
Closed this for now, since previous change was intended. |
For example, for this proto file:
We used to have:
Now:
It appears this changed in #2847 / #396, but it's unclear what the intent
was with these lines, so I'm assuming this was an unintended side-effect
(it's not needed to solve #1761).