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

pendulum DateTime type doesn't accept python standard datetime #139

Open
antti-ngp opened this issue Feb 8, 2024 · 0 comments
Open

pendulum DateTime type doesn't accept python standard datetime #139

antti-ngp opened this issue Feb 8, 2024 · 0 comments

Comments

@antti-ngp
Copy link

Glad the library includes the pendulum DateTime now. I was just starting to use it but noticed it doesn't accept the standard python datetime objects as expected.

Steps to reproduce:

from pydantic_extra_types.pendulum_dt import DateTime
import datetime
import pydantic

class MyTest(pydantic.BaseModel):
    my_pendulum_dt: DateTime

MyTest(my_pendulum_dt=datetime.datetime(2024,2,8,0,0,1))

Expected results:

MyTest(my_pendulum_dt=DateTime(2024, 2, 8, 0, 0, 1))

Actual results:

pydantic_core._pydantic_core.ValidationError: 1 validation error for MyTest
my_pendulum_dt
  value is not a valid timestamp [type=value_error, input_value=datetime.datetime(2024, 2, 8, 0, 0, 1), input_type=datetime]

Suggested fix:
Use pendulum.instance() for input of the type datetime.datetime before using pendulum.parse() for other types of input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant