Zeroes are not serialized with bytes() in proto2 syntax with required field
まだ誰も着手していません。
評価
調査の方向性
まず、生成された MyMessage と MyEnum.FOOBAR の例で問題を再現し、その後、必要な proto2 enum について bytes()、to_json()、to_dict() を比較します。include_default_values=True を要求しなくても、バイナリ表現にゼロ値の enum が含まれれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Summary
There should be an alternative bytes method that allows to serialize zeroes for proto2 syntax. Currently zeroes enums are skipped as they are "default" values which is incorrect because unless the field is optional, it must be present in encoded form.
Reproduction Steps
- Create a simple proto2 file:
message MyMessage {
enum MyEnum {
FOOBAR = 0;
BAZ = 1;
}
}
- Compile to python:
@dataclass
class MyMessage(betterproto.Message):
# @required
action: "MyEnum" = betterproto.enum_field(1)
class MyEnum(betterproto.Enum):
FOOBAR = 0
BAZ = 1
- Use the
FOOBARvalue (0):
print(
MyMessage(
action=MyEnum.FOOBAR,
)
)
You can see the MyEnum.FOOBAR here. However when you try to serialize it, the encoder skips this value incorrectly thinking it's default and hence shouldn't be added:
print(
MyMessage(
action=MyEnum.FOOBAR,
).to_json()
)
# or
print(
MyMessage(
action=MyEnum.FOOBAR,
).to_dict()
)
# or
print(
bytes(MyMessage(
action=MyEnum.FOOBAR,
))
)
This can only be "fixed" by passing include_default_values=True in to_json or to_dict:
print(
MyMessage(
action=MyEnum.FOOBAR,
).to_json(include_default_values=True)
)
But I need binary representation of the MyMessage class
Expected Results
N/A
Actual Results
N/A
System Information
Latest beta version
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 はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
danielgtaylor/python-betterproto のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
-
bug investigation needed
難易度 3/5 1〜2日 初心者へのやさしさ 42/100
-
bug investigation needed
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 10/100
danielgtaylor/python-betterproto#673 · コメント 1 件 ·
danielgtaylor/python-betterproto の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
khuisman/mcp-gee-sweet#1166 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
lugassawan/swe-workbench#823 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
gramaziokohler/compas_timber#870 ·
-
security-scan-failure
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
semantica-agi/semantica#2089 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
autowarefoundation/autoware_carla_scenario#500 ·
メンテナーはふだん 1 日以内に返信