Incorrect JSON serialization of repeated int64
还没有人认领这个 Issue。
评估
调研方向
首先使用生成的 ExampleContract 及其 to_json() 调用复现该问题,并将重复的 int64 项与包装的默认字段进行比较。跟踪生成的 Python 消息所使用的 JSON 序列化路径。当重复的 int64 值被序列化为数值 JSON 值、与预期输出一致,并且不改变包装字段的行为时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Summary
When I create a contract with a repeated int64 variable, it serializes into repeated string, which is an unpredictable behaviour
Reproduction Steps
- Create a contract:
// ExampleContract describes example of contract.
message ExampleContract {
// List of int64.
repeated int64 items = 1;
// Default int64 value.
google.protobuf.Int64Value default = 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."""
- 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: [email protected]
License: MIT
Location: /opt/conda/lib/python3.12/site-packages
Requires: grpclib, python-dateutil, typing-extensions
Checklist
- I have searched the issues for duplicates.
- I have shown the entire traceback, if possible.
- I have verified this issue occurs on the latest prelease of betterproto which can be installed using
pip install -U --pre betterproto, if possible.
- 主要语言
- Python
- 星标
- 1.8k
- 派生
- 235
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
danielgtaylor/python-betterproto 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 55/100
-
难度 5/5 一周以上 新手友好度 15/100
-
bug investigation needed
难度 3/5 1-2 天 新手友好度 42/100
-
bug investigation needed
难度 4/5 3-5 天 新手友好度 38/100
danielgtaylor/python-betterproto#676 · 3 条评论 ·
-
难度 5/5 一周以上 新手友好度 10/100
danielgtaylor/python-betterproto#673 · 1 条评论 ·
查看 danielgtaylor/python-betterproto 的全部 Issue
相似的 Issue
-
bug good first issue
难度 2/5 1-3 小时 新手友好度 78/100
yunaremaia/proto-drift#22 ·
-
bug good first issue
难度 2/5 1-3 小时 新手友好度 82/100
yunaremaia/memwatch#96 ·
-
bug good first issue
难度 1/5 1 小时以内 新手友好度 91/100
yunaremaia/ci-gate-watch#34 ·
-
bug good first issue
难度 2/5 1-3 小时 新手友好度 85/100
yunaremaia/agent-capability-attestation#64 ·
维护者通常 1 天内回复
-
bug good first issue
难度 1/5 1 小时以内 新手友好度 86/100
yunaremaia/agent-call-graph#43 ·
维护者通常 1 天内回复