kidok / protobuf

Automatically exported from code.google.com/p/protobuf
0 stars 0 forks source link

WhichOneof doesn't work on deserialized messages in Python #671

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile the test message from the python documentation:
message Foo {
  oneof test_oneof {
     string name = 1;
     int32 serial_number = 2;
  }
}

2. Run the script:
import foo_pb2

foo = foo_pb2.Foo()
foo.name = "bob"

assert foo.IsInitialized()
assert foo.HasField("name")
assert foo.WhichOneof("test_oneof") == "name"

ser = foo.SerializeToString()

foo2 = foo_pb2.Foo()
foo2.ParseFromString(ser)

assert foo2.IsInitialized()
assert foo2.HasField("name")

#This will fail
assert foo2.WhichOneof("test_oneof") == "name"

What is the expected output? What do you see instead?
foo2.WhichOneof("test_oneof") should return "name", it always returns None.

What version of the product are you using? On what operating system?
Python 2.7.6 on Ubuntu 14.04
python protobuf 2.6.0 (installed via pip from pypi)
protoc version libprotoc 2.6.0, compiled locally

Please provide any additional information below.
foo_pb2.py attached.

Original issue reported on code.google.com by brentala...@gmail.com on 10 Sep 2014 at 12:00

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by xiaof...@google.com on 10 Sep 2014 at 12:22

GoogleCodeExporter commented 9 years ago
Fixed in:
https://github.com/google/protobuf/commit/0971bb0d57aa6f2db1abee4008b365d52b4028
91

Original comment by xiaof...@google.com on 8 Oct 2014 at 12:55