yoav.weber
yoav.weber

Reputation: 31

Why is my protobuf map field represented as RepeatedCompositeFieldContainer in the generated Python code?

I have a .proto file that defines a message with a map<string, string> field:

syntax = "proto3";

message Message {

  map<string, string> map = 1;
}

After generating the Python code using buf, the map field is represented as RepeatedCompositeFieldContainer instead of a ScalarMap. Here is the generated Python code for the message:

class ExchangeAuthzCodeRequest(google.protobuf.message.Message):
    ...

    @property
    def access_token_vars(self) -> google.protobuf.internal.containers.ScalarMap[str, str]:
        ...

When I print the type of the access_token_vars field, I get:

print(type(proto_msg.access_token_vars))
# Output: <class 'google.protobuf.internal.containers.RepeatedCompositeFieldContainer'>

My Questions:

  1. Why is the map<string, string> field represented as RepeatedCompositeFieldContainer in the generated Python code and not as ScalarMap?
  2. Is this the expected behavior, or am I missing something in my protobuf definition or usage?

Additional Information:

version: v1
plugins:
- name: python
  out: .
- name: mypy
  out: .
- name: grpclib_python
  out: .

Upvotes: 1

Views: 107

Answers (0)

Related Questions