pydantic / pydantic-extra-types

Extra Pydantic types.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

chrisguidry opened this issue · comments

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

It seems like this may have been introduced in #184 or #185, I'm trying to narrow that down locally