googleapis / proto-plus-python

Beautiful, idiomatic protocol buffers in Python
Apache License 2.0
169 stars 35 forks source link

Messages with 'protobuf.Any' fields fail round trip dict construction #285

Open software-dov opened 2 years ago

software-dov commented 2 years ago

Consider the following snippet:

from google.protobuf import any_pb2
import proto

class Container(proto.Message):
    contents = proto.Field(any_pb2.Any, number=1)

class Thing(proto.Message):
    name = proto.Field(proto.STRING, number=1)

thing = Thing(name="Thing 1")
c = Container()
a = any_pb2.Any()
a.Pack(Thing.pb(thing))
c.contents = a

c_dict = Container.to_dict(c)
c_new = Container(mapping=c_dict)  # Raises an exception

This fails because the dict representation for any_pb2.Any contains metadata that proto.Message.__init__ and proto.Message.__setattr__ do not know how to handle/ignore properly.

This blocks the use of the REST transport for any API method with a request that contains an any_pb2.Any fields due to transcoding logic.

vchudnov-g commented 2 years ago

We are thinking about this issue, which affects multiple languages using protocol buffers over HTTP/JSON. We will continue providing updates, though the issue may not be completely resolved soon.

vchudnov-g commented 2 months ago

Note that when this issue is resolved, some corresponding tests in gapic-generator-python should be re-eneabled (example).