Open
Description
If a oneof
contains a submessage, and a field is assigned to this submessage, which_one_of
does not report the submessage. Here is a proto file, generated code and code to demonstrate the issue.
Proto:
syntax = "proto3";
message Inner {
int32 a = 1;
}
message Outer {
oneof which {
Inner inner = 1;
}
}
Generated code + reproduction of the bug:
from dataclasses import dataclass
import betterproto
@dataclass(eq=False, repr=False)
class Inner(betterproto.Message):
a: int = betterproto.int32_field(1)
@dataclass(eq=False, repr=False)
class Outer(betterproto.Message):
inner: "Inner" = betterproto.message_field(1, group="which")
test = Outer()
test.inner.a = 42
print(test) # Outer(inner=Inner(a=42))
print(betterproto.which_one_of(test, "which")) # ('', None) <-- WRONG
# Round trip encode / parse.
test2 = Outer().parse(bytes(test))
print(test2) # Outer(inner=Inner(a=42))
print(betterproto.which_one_of(test2, "which")) # ('inner', Inner(a=42)) <-- correct