pydantic / pydantic-extra-types

Extra Pydantic types.
MIT License
176 stars 47 forks source link

Pendulum `DateTime` wrapper losing `tz` and `timezone` values in 2.8.1 #188

Closed chrisguidry closed 2 months ago

chrisguidry commented 2 months ago

After upgrading to pydantic-extra-types==2.8.1, we're seeing some bizarre artifacts with timezones for the Pendulum wrapper types.

Repro:

from datetime import timedelta

from pydantic import BaseModel
from pydantic_extra_types.pendulum_dt import DateTime

class MyModel(BaseModel):
    dt: DateTime

m = MyModel(dt="2021-02-03T04:05:06.777777Z")

# The timezone appears to be set...
print(m.dt)
# ..., but when doing date math, it is dropped
print(m.dt - timedelta(seconds=10))

# Only the tzinfo is set, the others are None
print("tzinfo:", m.dt.tzinfo)
print("tz:", m.dt.tz)
print("timezone:", m.dt.timezone)

2.8.0:

$ pip install pydantic-extra-types==2.8.0 && python repro.py 
...
2021-02-03 04:05:06.777777+00:00
2021-02-03 04:04:56.777777+00:00
tzinfo: UTC
tz: UTC
timezone: UTC

2.8.1:

$ pip install pydantic-extra-types==2.8.1 && python repro.py 
...
2021-02-03 04:05:06.777777+00:00
2021-02-03 04:04:56.777777        <-- here the timezone is gone
tzinfo: UTC
tz: None
timezone: None
chrisguidry commented 2 months ago

It seems like this may have been introduced in https://github.com/pydantic/pydantic-extra-types/pull/184 or https://github.com/pydantic/pydantic-extra-types/pull/185, I'm trying to narrow that down locally