Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datetime support in .from_dict() #33

Open
Kyle-sandeman-mrdfood opened this issue Apr 21, 2020 · 2 comments
Open

datetime support in .from_dict() #33

Kyle-sandeman-mrdfood opened this issue Apr 21, 2020 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers low priority small Low effort issue that can easily be picked up
Projects
Milestone

Comments

@Kyle-sandeman-mrdfood
Copy link

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?

@boukeversteegh boukeversteegh added this to Backlog in Betterproto May 25, 2020
@boukeversteegh boukeversteegh added bug Something isn't working good first issue Good for newcomers small Low effort issue that can easily be picked up labels May 25, 2020
@boukeversteegh boukeversteegh added this to the Better Types milestone May 25, 2020
@alfredgunnar
Copy link

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

@meg2208
Copy link

meg2208 commented May 4, 2023

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers low priority small Low effort issue that can easily be picked up
Projects
Betterproto
  
Backlog
Development

No branches or pull requests

4 participants