danielgtaylor / danielgtaylor/python-betterproto
`to_dict` or `to_pydict` miss integer and boolean fields
- Vorherrschende Sprache
- Python
- Sterne
- 1.8k
- Forks
- 234
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
when i use `to_dict` or `to_pydict` function to serialize message, `False` and `0` values are not work for boolean and integer fields.
here is the sample code:
```python3
from dataclasses import dataclass
import betterproto
@dataclass
class Greeting(betterproto.Message):
"""Greeting represents a message you can tell a user."""
int_field: int = betterproto.int32_field(1)
bool_field: bool = betterproto.bool_field(2)
if __name__ == "__main__":
greeting = Greeting(
int_field=0,
bool_field=False
)
print(greeting.to_pytdict())
greeting.int_field = 1
greeting.bool_field = True
print(greeting.to_pydict())
```
and output is:
```
{}
{'intField': 1, 'boolField': True}
```
python version: 3.8
betterproto version: 2.0.0b5
Beitragsleitfaden
Rechercherichtung
Start by reproducing the Greeting example with Python 3.8 and compare to_pydict output for default-valued integer and boolean fields with the output for truthy values. Trace the to_dict or to_pydict serialization path; done when 0 and False are serialized correctly without changing existing behavior.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend-api-design
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100