Inconsistency with google protobuf when converting to dict/json with include_default_values=True
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
- 38/100
Hướng nghiên cứu
Start with the Message.to_dict(include_default_values=True) entry point and compare its output with google.protobuf.json_format.MessageToDict using the linked reproduction repository. Add coverage for the shown oneof case; done means only the active variant appears in dict and JSON output when default values are included.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
When converting a message to dict (or to json) with include_default_values set to True, the dict/json message will contain all variants for a oneof, not just the set one.
This is inconsistent with the google protobuf library, and it can IMHO be confusing especially when variants are complex messages (as all the nested fields of all the variants will be contained in the dict/json)
Reproduction Steps
I created a simple repo to reproduce this, with a slightly more complete example, here.
But basically, given a message with a oneof field eg.
syntax = "proto3";
message Message {
oneof root_field {
int32 int_value = 1;
string string_value = 2;
}
}
Convert it to dict setting the including_default_values flag to True
from betterproto_compiled import Message
from pprint import pprint
message = Message(
int_value=10
)
pprint(message.to_dict(include_default_values=True))
Expected Results
I expected to obtain a dict with only the active variant of the oneof being included (which is the same behavior as the MessageToDict from the standard python protobuf library).
This is the output I get from google.protobuf.json_format.MessageToDict, setting including_default_value_fields=True:
{'intValue': 10}
Actual Results
A dict with all the variants of the oneof, including the non-set ones:
{'intValue': 10, 'stringValue': ''}
System Information
libprotoc 3.21.6
Python 3.10.13
Name: betterproto
Version: 2.0.0b6
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: /home/marco/.local/share/rtx/installs/python/3.10.13/lib/python3.10/site-packages
Requires: grpclib, python-dateutil
Required-by:
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
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của danielgtaylor/python-betterproto
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
-
bug investigation needed
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
-
bug investigation needed
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
-
bug investigation needed
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
danielgtaylor/python-betterproto#676 · 3 bình luận ·
Tất cả issue của danielgtaylor/python-betterproto
Issue tương tự
-
Validate non-divisible effective batch sizes in the Unsloth LoRA backendCó thể đã có người làm @debesh-biswas đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
`rx.Model` event arguments emit `PydanticDeprecatedSince20` once per payload keyCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
reflex-dev/reflex#7634 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
documentation
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 82/100
topoteretes/cognee#6239 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ranaroussi/yfinance#3009 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Test discovery aborts on GPU builds without cuStateVec: check_cuStateVec expects a failed result but set_config() now raises RuntimeErrorCó thể đã có người làm @dmeliksetian đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Qiskit/qiskit-aer#2495 ·
Maintainer thường phản hồi trong vòng 1 ngày