Implicit optional is not respected
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
Hướng nghiên cứu
Tái hiện vấn đề với Sample proto được cung cấp và dataclass Python đã生成, sau đó theo dõi cách khai báo field và quá trình tuần tự hóa bytes(Sample(foo=False)) xử lý các optional fields ngầm định so với các optional fields tường minh. Được xem là hoàn tất khi các field ngầm định tuần tự hóa các giá trị mặc định một cách nhất quán với các optional fields tường minh và khớp với hành vi protobuf được ghi trong tài liệu.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
When you don't add an explicit optional, fields are not serialized properly if they happen to be set to the default value.
Reproduction Steps
message Sample {
bool foo = 1
}
generates
[
{
"name": "foo",
"type": "BOOLEAN",
"mode": "NULLABLE",
}
]
but the python code generated is
@dataclass(eq=False, repr=False)
class Sample(betterproto.Message):
foo: bool = betterproto.string_field(1)
which implies that the boolean is non-nullable.
Then, if we do
bytes(Sample(foo=False))
it will be serialized to
b''
and actually treated as null.
If we change the proto to
message Sample {
optional bool foo = 1
}
then the correct code is generated and the message is serialized as expected.
Actual Results
The protobuf documentation suggests that not setting optional should be treated in the same way as setting it.
System Information
libprotoc 28.3
Python 3.10.11
betterproto 2.0.0b7
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ự
-
type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
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
Maintainer thường phản hồi trong vòng 1 ngày
-
push_gh-pages fails on master branch on forksCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởgood first issue infrastructure
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
kuznia-rdzeni/coreblocks#1135 ·
-
good first issue server
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation priority: high
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
a-lex-s/mealie-telegram-bot#54 ·
Maintainer thường phản hồi trong vòng 1 ngày