Protobuf: mixing with optional fields: core dump --experimental_allow_proto3_optional

Created on 5 May 2020  路  3Comments  路  Source: protocolbuffers/protobuf

Version: v3.12.0-rc-1
Language: Python3.7.5
Operating system: linux-x86_64
(Linux cortex-vbox 5.3.0-51-generic #44-Ubuntu SMP Wed Apr 22 21:09:44 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux)

protoc pre-compile:
https://github.com/protocolbuffers/protobuf/releases/download/v3.12.0-rc1/protoc-3.12.0-rc-1-linux-x86_64.zip

Install:
pip install protobuf==3.12.0-rc1

It appears the new (3.12.0-rc-1) optional fields work if all singular fields in a message are optional:

message PbTest {
    optional string test_string = 1;
    optional bool test_bool = 2;
    optional int32 test_int32 = 3;
}
>>> from cylc.flow.data_messages_pb2 import PbWorkflow, PbTest
>>> test1 = PbTest(test_string='foo', test_bool=True, test_int32=1234)
>>> test1
test_string: "foo"
test_bool: true
test_int32: 1234
>>> test2 = PbTest(test_string='', test_bool=False, test_int32=0)
>>> test2
test_string: ""
test_bool: false
test_int32: 0
>>> test1.MergeFrom(test2)
>>> test1
test_string: ""
test_bool: false
test_int32: 0



md5-2e885a61bfc79c746f77eb947d1b6552



message PbTest {
    string no_opt_string = 1;
    optional string test_string = 2;
    //optional bool test_bool = 2;
    //optional int32 test_int32 = 3;
}



md5-74ec5572326ede780c4db0e4ac4a4edb



>>> from cylc.flow.data_messages_pb2 import PbWorkflow, PbTest
>>> test1 = PbTest()
>>> test1
[libprotobuf FATAL google/protobuf/generated_message_reflection.cc:1015] CHECK failed: (has_bit_index) != (~0u): 
terminate called after throwing an instance of 'google::protobuf::FatalException'
  what():  CHECK failed: (has_bit_index) != (~0u): 
Aborted (core dumped)



md5-01a45fb6a9c00a3f55c437c133547d90



message PbMeta {
    string title = 1;
    string description = 2;
    string URL = 3;
    repeated string user_defined = 4;
}
message PbTest {
    //repeated string no_opt_strings = 1;
    optional string test_string = 2;
    Meta meta = 3;
    //optional bool test_bool = 2;
    //optional int32 test_int32 = 3;
}

(optional single message fields do work)

Most helpful comment

Thank you for the report, and for trying out a prerelease package! I have reproduced the error and will make sure a fix is in before 3.12.0 is released.

All 3 comments

Thank you for the report, and for trying out a prerelease package! I have reproduced the error and will make sure a fix is in before 3.12.0 is released.

The fix for this is released in https://github.com/protocolbuffers/protobuf/releases/tag/v3.12.0-rc2.

Thanks @haberman ! . . . legend.

We'll implement this version in the coming week, thanks again 馃憤

Was this page helpful?
0 / 5 - 0 ratings