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

Error when calling to_pydict on a message having a repeated timestamp field

Đang mở
#617 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
35/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, backend

Hướng nghiên cứu

Tái hiện vấn đề với định nghĩa Msg và giá trị datetime được cung cấp, sau đó truy vết đường dẫn chuyển đổi to_pydict xử lý repeated fields và các giá trị google.protobuf.Timestamp. Được coi là hoàn tất khi to_pydict hoàn thành mà không có AttributeError và trả về biểu diễn repeated timestamp như mong đợi, khớp với hành vi hoạt động của to_dict.

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

Mô tả

bug investigation needed

When calling the to_pydict method on a message which has a repeated timestamp field, an AttributeError is raised.

Reproduction Steps

Compile the following message :

message Msg {
    repeated google.protobuf.Timestamp ts = 1;
}

Then, execute the following code:

from datetime import datetime

msg = Msg(ts=[datetime(2015, 3, 5)])

print(msg.to_dict())
print(msg.to_pydict())
Expected Results

In this situation, it is expected for the two calls to work without error.

Actual Results

The call to to_dict works as expected: it prints {'ts': ['2015-03-05T00:00:00Z']}. However, the call to to_pydict fails with the error: AttributeError: 'datetime.datetime' object has no attribute 'to_pydict'.

It is possible to simply fix this bug (and the related bugs) by patching the to_pydict function, but it might be easier with a bit of refactoring first. I will probably be able to work on this once my other PRs are approved.

System Information

libprotoc 3.12.4
Python 3.12.5
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: XXX/.venv/lib/python3.12/site-packages
Requires: grpclib, python-dateutil, typing-extensions
Required-by: pygrpc-poc

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.