Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Incorrect JSON serialization of repeated int64

Đang mở
#677 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
api

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện vấn đề với ExampleContract được tạo và lệnh gọi to_json() của nó, so sánh các phần tử int64 lặp lại với trường mặc định được bao bọc. Truy vết đường dẫn tuần tự hóa JSON được message Python được tạo sử dụng. Công việc được hoàn tất khi các giá trị int64 lặp lại được tuần tự hóa thành các giá trị JSON dạng số, khớp với đầu ra mong đợi, mà không thay đổi hành vi của trường được bao bọc.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.
Ngôn ngữ chính
Python
Star
1.8k
Fork
235
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của danielgtaylor/python-betterproto

Tất cả issue của danielgtaylor/python-betterproto

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.