danielgtaylor / danielgtaylor/python-betterproto

datetime support in .from_dict()

Open
#33 2 comments 0 reactions 0 assignees View on GitHub
bug good first issue low priority small
Dominant language
Python
Stars
1.8k
Forks
234
PR merge metrics
No merged PRs in 30d

Description

Good day, assuming I have
`d = {'date_of_birth': datetime.datetime(2000)}`
and a `proto` including
`date_of_birth: Timestamp`:
When `proto.from_dict(d)` is called, it assumes the value of date_of_birth is an ISO string and does not consider that it may already be a `datetime.datetime`

I refer to your `__init__.py` L799-803:
```
elif isinstance(v, datetime):
v = datetime.fromisoformat(
value[key].replace("Z", "+00:00")
)
setattr(self, field.name, v)
```
This should check if `value[key]` is already an instance of `datetime.datetime` and assign it directly, shouldn't it?

Contributor guide

Open the contributing guide

Research direction

Start in __init__.py around lines 799-803 and trace the .from_dict() handling for Timestamp fields. Verify the behavior for both an existing datetime.datetime value and an ISO-format string; done means datetime inputs are assigned without string conversion while string inputs retain their current parsing behavior.

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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.