danielgtaylor / danielgtaylor/python-betterproto
nested empty types not in to_dict
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 234
- PR merge metrics
- No merged PRs in 30d
Description
I am not sure if I am wrong here but when executing this:
```python
from dataclasses import dataclass
import betterproto
@dataclass
class Inner(betterproto.Message):
inner1: str = betterproto.string_field(1)
inner2: str = betterproto.string_field(2)
@dataclass
class Test(betterproto.Message):
name: str = betterproto.string_field(1)
inner: "Inner" = betterproto.message_field(2)
test = Test(name='123', inner=Inner())
print(test.to_json())
```
I receive the output `{"name": "123"}`. I would expect the output to be`{"name": "123", inner:{}}`.
Of course there is a similar issue with the `to_dict` function
Contributor guide
Research direction
Run the provided Python reproduction first, then inspect the implementations of Message.to_json and Message.to_dict. Done means an initialized empty Inner message is retained as an empty nested object in both outputs, while the existing name field remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100