Status: New
Owner: liuj...@google.com
Labels: Type-Defect Priority-Medium

New issue 278 by muzuiget: SerializeToString fail if nested types all field is empty
http://code.google.com/p/protobuf/issues/detail?id=278

version protobuf-2.4.0a, python2.6 ubuntu 10.10 install from source tarball with easy_install.

If define a proto file as below

$cat test.proto
message Child {
        repeated int32 a = 1;
        repeated int32 b = 2;
}

message Partent {
        required Child child = 1;
}

generate a python class file, run code as below

$ cat test1.py
import test_pb2
p = test_pb2.Partent()
print p
p.SerializeToString()

$ python test1.py

Traceback (most recent call last):
  File "test1.py", line 4, in <module>
    p.SerializeToString()
File "/usr/local/lib/python2.6/dist-packages/protobuf-2.4.0a-py2.6.egg/google/protobuf/internal/python_message.py", line 730, in SerializeToString
    ','.join(self.FindInitializationErrors()))
google.protobuf.message.EncodeError: Message is missing required fields: child

Because both child.a and child.b are empty, it cause child empty. A solution is change the Child tag to "optional".

I don't know it is a feature or bug. But if I run

$ cat test2.py
import test_pb2
p = test_pb2.Partent()
print p
print p.child.a
p.child.a.append(1)
p.child.a.remove(1)
print p
print p.child.a
p.SerializeToString()

$ python test2.py

[]
child {
}

[]

After append and remove, child.a and child.b sitll empty, but this time child is not empty, SerializeToString success.


--
You received this message because you are subscribed to the Google Groups "Protocol 
Buffers" group.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to