danielgtaylor / danielgtaylor/python-betterproto

Incorrect JSON serialization of repeated int64

Aperta
#677 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug investigation needed
Lingua principale
Python
Stelle
1.8k
Fork
234
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### 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.

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.