danielgtaylor / danielgtaylor/python-betterproto

which_one_of returns incorrect value for nested assignments

Abierto
#305 4 comentarios 0 reacciones 1 asignado Reclamado por @cetanu Ver en GitHub
bug
Lenguaje dominante
Python
Estrellas
1.8k
Forks
234
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.