danielgtaylor / danielgtaylor/python-betterproto
to_dict() fails to write boolean fields without default when value is False
- 主要言語
- Python
- スター
- 1.8k
- フォーク
- 234
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
When you have a message with a boolean value as follows:
```
message Patient {
bool isRnaAvailable = 1;
}
```
then an object like
```
patient = Patient()
patient.is_rna_available = np.random.choice([True, False], 1)[0]
```
fails to write the `is_rna_available` field when it is False when calling `patient.to_dict()`, this does not happen when the value is True.
The issue seems to be in line 824 of file `betterproto/__init__py` where it runs the following comparison `elif v != self._get_field_default(field, meta) or include_default_values:`. It should be something like 'elif v != None or include_default_values', otherwise when you set a field to the same value as the default value and do not set `include_default values` then it is not written. This may be also the case for other types.
コントリビューションガイド
調査の方向性
betterproto/__init__.py の 824 行目付近にある to_dict() のロジックから始め、is_rna_available を False に設定した Patient の例を再現してください。デフォルト値と等しいフィールドが、他のフィールド型も含めてどのように扱われるかを確認し、結果の Dictionary が include_default_values を必要とせず、明示的に代入された False 値を保持することを検証してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- api, backend
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100