python-betterproto icon indicating copy to clipboard operation
python-betterproto copied to clipboard

datetime support in .from_dict()

Open Kyle-sandeman-mrdfood opened this issue 5 years ago • 2 comments

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?

Kyle-sandeman-mrdfood avatar Apr 21 '20 09:04 Kyle-sandeman-mrdfood

+1 on this. I just bumped into the same issue.

alfredgunnar avatar Oct 21 '21 13:10 alfredgunnar

+1

meg2208 avatar May 04 '23 22:05 meg2208