danielgtaylor / danielgtaylor/python-betterproto
`to_dict` or `to_pydict` miss integer and boolean fields
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 234
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
Research direction
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.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100