python-betterproto icon indicating copy to clipboard operation
python-betterproto copied to clipboard

An empty message in a repeated field will be serialized to empty bytes

Open livelxw opened this issue 5 years ago • 1 comments

Given

syntax = "proto3";

message MessageA {
  repeated float field_a = 1;
}

message MessageB {
  repeated MessageA field_b = 1;
}

When

s = MessageB(field_b=[MessageA()]).SerializeToString()

Then s will be b'' and if call MessageB.FromString(s) the result will be MessageB() (different from MessageB(field_b=[MessageA()])). But in some other protobuf libraries like Scalapb the serialized string will be \n\000. If call MessageB.FromString(b'\n\000') the result will be MessageB(field_b=[MessageA()])(the expected result). Is this a bug?

livelxw avatar Nov 30 '20 13:11 livelxw

It looks like we differ from the google implementation in this respect, so yes I'd say it is a bug. Thanks for reporting.

nat-n avatar Nov 30 '20 19:11 nat-n

Fixed in #180

Gobot1234 avatar Aug 31 '22 13:08 Gobot1234