danielgtaylor / danielgtaylor/python-betterproto
Error when calling to_pydict on a message having a repeated timestamp field
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 234
- PR merge metrics
- No merged PRs in 30d
Description
When calling the `to_pydict` method on a message which has a repeated timestamp field, an `AttributeError` is raised.
### Reproduction Steps
Compile the following message :
```
message Msg {
repeated google.protobuf.Timestamp ts = 1;
}
```
Then, execute the following code:
```python
from datetime import datetime
msg = Msg(ts=[datetime(2015, 3, 5)])
print(msg.to_dict())
print(msg.to_pydict())
```
### Expected Results
In this situation, it is expected for the two calls to work without error.
### Actual Results
The call to `to_dict` works as expected: it prints `{'ts': ['2015-03-05T00:00:00Z']}`. However, the call to `to_pydict` fails with the error: `AttributeError: 'datetime.datetime' object has no attribute 'to_pydict'`.
It is possible to simply fix this bug (and the related bugs) by patching the `to_pydict` function, but it might be easier with a bit of refactoring first. I will probably be able to work on this once my other PRs are approved.
### System Information
libprotoc 3.12.4
Python 3.12.5
Name: betterproto
Version: 2.0.0b7
Summary: A better Protobuf / gRPC generator & library
Home-page: https://github.com/danielgtaylor/python-betterproto
Author: Daniel G. Taylor
Author-email: danielgtaylor@gmail.com
License: MIT
Location: XXX/.venv/lib/python3.12/site-packages
Requires: grpclib, python-dateutil, typing-extensions
Required-by: pygrpc-poc
### Checklist
- [X] I have searched the issues for duplicates.
- [X] I have shown the entire traceback, if possible.
- [X] I have verified this issue occurs on the latest prelease of betterproto which can be installed using `pip install -U --pre betterproto`, if possible.
Contributor guide
Assessment
This issue has not been assessed yet.