Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Incorrect JSON serialization of repeated int64

未关闭
#677 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
api

调研方向

首先使用生成的 ExampleContract 及其 to_json() 调用复现该问题,并将重复的 int64 项与包装的默认字段进行比较。跟踪生成的 Python 消息所使用的 JSON 序列化路径。当重复的 int64 值被序列化为数值 JSON 值、与预期输出一致,并且不改变包装字段的行为时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

bug investigation needed
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:
// ExampleContract describes example of contract.
message ExampleContract {
  // List of int64.
  repeated int64 items = 1;
  // Default int64 value.
  google.protobuf.Int64Value default = 2;
}
  1. 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."""
  1. 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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

danielgtaylor/python-betterproto 的其他 Issue

查看 danielgtaylor/python-betterproto 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。