danielgtaylor / danielgtaylor/python-betterproto
Incorrect JSON serialization of repeated int64
- Lenguaje dominante
- Python
- Estrellas
- 1.8k
- Forks
- 234
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
### Summary
When I create a contract with a repeated int64 variable, it serializes into repeated string, which is an unpredictable behaviour
### Reproduction Steps
1. Create a contract:
````protobuf
// ExampleContract describes example of contract.
message ExampleContract {
// List of int64.
repeated int64 items = 1;
// Default int64 value.
google.protobuf.Int64Value default = 2;
}
````
2. Compile to python:
```
@dataclass(eq=False, repr=False)
class ExampleContract(betterproto.Message):
"""
ExampleContract describes example of contract.
"""
items: List[int] = betterproto.int64_field(1)
"""List of int64."""
default: Optional[int] = betterproto.message_field(2, wraps=betterproto.TYPE_INT64)
"""Default int64 value."""
```
3. Create instance of class and serialize it to JSON:
```
ec = ExampleContract(items=[5, 10], default=10)
print(ec.to_json())
```
### Expected Results
{"items": [5, 10], "default": 10}
### Actual Results
{"items": ["5", "10"], "default": 10}
### System Information
libprotoc 25.3, Python 3.12.7
Name: betterproto
Version: 2.0.0b7
Summary: A better Protobuf / gRPC generator & library
Home-page: https://github.com/danielgtaylor/python-betterproto
Author: Daniel G. Taylor
Author-email: danielgtaylor@gmail.com
License: MIT
Location: /opt/conda/lib/python3.12/site-packages
Requires: grpclib, python-dateutil, typing-extensions
### Checklist
- [x] I have searched the issues for duplicates.
- [x] I have shown the entire traceback, if possible.
- [x] I have verified this issue occurs on the latest prelease of betterproto which can be installed using `pip install -U --pre betterproto`, if possible.
Guía de contribución
Línea de trabajo
Empieza reproduciendo el problema con el ExampleContract generado y su llamada a to_json(), comparando los elementos int64 repetidos con el campo predeterminado envuelto. Rastrea la ruta de serialización JSON utilizada por el mensaje Python generado. La tarea estará terminada cuando los valores int64 repetidos se serialicen como valores JSON numéricos, coincidiendo con la salida esperada, sin cambiar el comportamiento del campo envuelto.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- api
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100