Skip to content

Membership test of a key in Map have different behavior in Python & CPP API  #4029

@cyyber

Description

@cyyber

Recently, I have faced an issue using protobuf in Python3, where CPP environ works fine, but python environ fails to find the key. This behavior has recently caused disruption to the distribution of our software using protobuf.

Lets assume the following protoformat

message myData {
map<string, uint64> data = 1;
}

Now lets assume I set the cpp environment I do the following after generating stub.

os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'cpp'
myData.data['hello'] = 10
print(b'hello' in myData.data)

The above would print True, in cpp api of protobuf.
Now lets do the same with python

os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python'
myData.data['hello'] = 10
print(b'hello' in myData.data)

The above would print False as python api doesn't convert bytes into string.

Due to this, our software, using protobuf, when deployed into different nodes of our users, had mixed result. Users with cpp api of protobuf, in their nodes, our software worked fine, without any problem. But users with the python api of protobuf, had faced a lot of bug just because of this.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions