protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Ruby hash of hash is not supported, ArgumentError: Unknown field name 'bar' in initialization map entry.

Open anjali-globallogic opened this issue 5 years ago • 2 comments

Version: 3.11.4 Language: Ruby

operating system Ubuntu-18.04.4 LTS

Steps to reproduce the behavior: I am implementing a client in Ruby. While passing parameters to server call, I am encountering this issue. Ruby Hash of Hash is not supported by grpc, it's giving ArgumentError: Unknown field name 'bar' in initialization map entry.

In my service_pb.rb file I have:

add_message 'request' do
  ...
  optional :test, :message, 12, 'google.protobuf.Struct'
end

Now I am trying to pass the request params in my client.rb:

params = {xyz: "abc", test: { bar: "296" }}
stub = Message::Stub.new('localhost:9999', :this_channel_is_insecure)
msg = Request.new(params)

while running this I am getting: ArgumentError: Unknown field name 'bar' in initialization map entry.

It should not ask for keys to be present in map entry since keys are dynamic data.

anjali-globallogic avatar May 11 '20 17:05 anjali-globallogic

Sorry for the late response. Are you still seeing this error in newer versions of protobuf?

deannagarcia avatar Jul 26 '22 21:07 deannagarcia

I want to clarify, I think the feature request here is to support hash initialization of struct fields:

Google::Protobuf::Struct.new({foo: "bar"})

I agree this would be nice. The main risk is that this would be backward-incompatible. Currently it is possible to write:

Google::Protobuf::Struct.new({fields: {foo: {string_value: "bar"}}})

If we implemented the feature requested in this issue, the above would have a different meaning. So we would probably need to make this change in a major version.

One thing you can do right now is:

msg = Request.new
msg.test = { bar: "296" }

haberman avatar Sep 01 '22 21:09 haberman

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

github-actions[bot] avatar Mar 11 '24 10:03 github-actions[bot]

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.

This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

github-actions[bot] avatar Mar 27 '24 10:03 github-actions[bot]