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

Closed
antti-ngp opened this issue Feb 8, 2024 · 1 comment
Closed

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

antti-ngp opened this issue Feb 8, 2024 · 1 comment

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.

@07pepa
Copy link
Contributor

07pepa commented Jun 1, 2024

@yezz123 this can be closed already present here with test and merged #176

@yezz123 yezz123 closed this as completed Jun 1, 2024
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

3 participants