[ruby] Detecting map types via descriptors

101 views
Skip to first unread message

Maxime Liron

unread,
Nov 26, 2024, 4:20:15 AM11/26/24
to Protocol Buffers
Hey!

I'm upgrading my app's google-protobuf ruby gem dep from 3.25.3 to 4.28.2.

I had code that would check message descriptors to detect map types. It's now raising.

I used to do `descriptor.type == :message && descriptor.subtype.options.map_entry` to check if a message is a map.

Now this raises a rather cryptic `Cannot find MessageOptions in DescriptorPool`.
Seems like any call of `.options` on any message descriptor in my codebase raises this error.

Any suggestions on how to detect a map now?

```
> bundle exec grpc_tools_ruby_protoc --version
libprotoc 27.2
```

Maxime Liron

unread,
Dec 1, 2024, 6:21:35 PM12/1/24
to Protocol Buffers
require 'google/protobuf/descriptor_pb'

Jason Lunn

unread,
Dec 2, 2024, 11:39:47 AM12/2/24
to Protocol Buffers
Can you provide a brief example that reproduces the issue?

When I try building my own example, it appears to work as you describe it works as expected:

host:~$ irb
irb(main):001> require 'google/protobuf/descriptor_pb'
=> true
irb(main):002> Google::Protobuf::FieldDescriptorProto.descriptor.lookup("options")
=> #<Google::Protobuf::FieldDescriptor:0x00007ffa48705ab8>
irb(main):003> Google::Protobuf::FieldDescriptorProto.descriptor.lookup("options").type
=> :message
irb(main):004> Google::Protobuf::FieldDescriptorProto.descriptor.lookup("options").subtype
=> #<Google::Protobuf::Descriptor:0x00007ffa48862000>
irb(main):005> Google::Protobuf::FieldDescriptorProto.descriptor.lookup("options").options
=> <Google::Protobuf::FieldOptions: targets: [], edition_defaults: [], uninterpreted_option: []>
irb(main):006> Google::Protobuf::FieldDescriptorProto.descriptor.lookup("options").subtype.options
=> <Google::Protobuf::MessageOptions: uninterpreted_option: []>
irb(main):007> Google::Protobuf::FieldDescriptorProto.descriptor.lookup("options").subtype.options.map_entry
=> false
Reply all
Reply to author
Forward
0 new messages