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

[BUG] Serializing datetime.time loses timezone data when datetime.datetime is reqired for utc offset because of DST #1287

Open
07pepa opened this issue May 2, 2024 · 0 comments
Assignees

Comments

@07pepa
Copy link

07pepa commented May 2, 2024

Since i encountered this issue while re-implementing your serialization of time for beanie in python (BeanieODM/beanie#912)

there is issue when zone info can't get you precise utc offset without some date time (because of DST)

i know folowimg code this is pydantic... but what causes error is in here

pub fn pytime_as_time(py_time: &Bound<'_, PyAny>, py_dt: Option<&Bound<'_, PyAny>>) -> PyResult<Time> {

and here

Self::Py(py_time) => pytime_as_time(py_time, None),

    from pydantic import BaseModel
    from datetime import time
    from zoneinfo import ZoneInfo
    class TimeTest(BaseModel):
        t: time


    assert (TimeTest(t=time(12, 4, 5, 123456, tzinfo=ZoneInfo("America/Fortaleza")))
            .model_dump(mode="json")) != (TimeTest(t=time(12, 4, 5, 123456, tzinfo=ZoneInfo("Europe/Prague")))
                                          .model_dump(mode="json")) #fails

you can see it causes loss of data and is and there is way how to safely cover 99% of timezones (see my python implementation)

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

No branches or pull requests

2 participants