oneof inside nested message

29 views
Skip to first unread message

Adrian Schlatter

unread,
Dec 9, 2019, 5:52:12 AM12/9/19
to Protocol Buffers
Hi,

I am facing a problem with oneof {} inside a nested message and Python 3.7 (not sure whether it is limited to Python 3.7 or even to Python in general). Example:

demo.proto
syntax = "proto3";

package oneofInsideNestedMessage;

message outside
{
    message inside
{
        oneof dummyName
{
               
MsgA a = 1;
               
MsgB b = 2;
       
}
   
}
}

message
MsgA {
       
string text = 1;
}

message
MsgB {
        uint32 number
= 1;
}


demo.py:
from demo_pb2 import outside

msg
= outside()
msg
.inside.a.text = 'test'

Result:

I expect that this will

a) choose MsgA as type for the oneof {
b) set text field to 'test'

What actually happens:

Traceback (most recent call last):

 
File "<ipython-input-6-da73825bef90>", line 1, in <module>
    runfile
('.../demo.py', wdir='...')

 
File "...\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile
(filename, namespace)

 
File "...\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
   
exec(compile(f.read(), filename, 'exec'), namespace)

 
File ".../demo.py", line 11, in <module>
    msg
.inside.a.text = 'test'

AttributeError: '_FieldProperty' object has no attribute 'text'

It does not happen when oneof is located in "outside" only when in "inside". As I want to switch an existing format to protobuf I do not want to change the structure of the data as this would break existing application code. Is this considered a bug (i.e., will go away eventually) or is this a limitation that will remain?

Best regards and thanks for making protobuf available publicly,
Adrian
Reply all
Reply to author
Forward
0 new messages