danielgtaylor / danielgtaylor/python-betterproto

which_one_of returns incorrect value for nested assignments

Aperta
#305 4 commenti 0 reazioni 1 assegnatario Rivendicata da @cetanu Vedi su GitHub
bug
Lingua principale
Python
Stelle
1.8k
Fork
234
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.