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] ODM model can't get datetime timezone #1110

Open
DotJM opened this issue Jan 21, 2025 · 2 comments
Open

[BUG] ODM model can't get datetime timezone #1110

DotJM opened this issue Jan 21, 2025 · 2 comments

Comments

@DotJM
Copy link

DotJM commented Jan 21, 2025

Describe the bug
When saving and loading datetime type information using ODM, timezone information disappears.

To Reproduce

  • model
class TestDocs(Document, extra="allow", populate_by_name=True):
id: Indexed(str) = Field(..., alias="_id") # type: ignore

created: Optional[datetime] = None
modified: Optional[datetime] = None

Expected behavior
When saving, information should be saved to mongodb and loaded according to the timezone information of the datetime in the model.

Additional context
When imported, it is loaded without timezone information.

@DotJM DotJM changed the title [BUG] ODM model can get datetime timezone [BUG] ODM model can't get datetime timezone Jan 21, 2025
@staticxterm
Copy link
Contributor

Hi,

this is not an issue with Beanie, you have to configure timezone awareness setting in Motor/PyMongo:
https://www.mongodb.com/docs/languages/python/pymongo-driver/current/data-formats/dates-and-times/#aware-utc-datetime

Please provide a minimum runnable and reproducible example if the issue still persists.

Copy link
Contributor

This issue is stale because it has been open 30 days with no activity.

@github-actions github-actions bot added the Stale label Feb 22, 2025
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