danielgtaylor / danielgtaylor/python-betterproto
Incorrect JSON serialization of repeated int64
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 234
- PR merge metrics
- No merged PRs in 30d
Description
### 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.
Contributor guide
Assessment
This issue has not been assessed yet.