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

[DH-5212] Fix UTC timezone #332

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 3 additions & 23 deletions dataherald/api/types/responses.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime, timezone
from datetime import datetime

from pydantic import BaseModel, validator
from pydantic import BaseModel

from dataherald.db_scanner.models.types import TableDescription
from dataherald.sql_database.models.types import DatabaseConnection
Expand All @@ -9,17 +9,7 @@
class BaseResponse(BaseModel):
id: str
metadata: dict | None
created_at: str | None

@validator("created_at", pre=True, always=True)
def created_at_as_string(cls, v):
if not v:
return None
if isinstance(v, datetime):
return str(v.replace(tzinfo=timezone.utc))
if isinstance(v, str):
return v
return None
created_at: datetime | None


class PromptResponse(BaseResponse):
Expand All @@ -37,16 +27,6 @@ class SQLGenerationResponse(BaseResponse):
confidence_score: float | None
error: str | None

@validator("completed_at", pre=True, always=True)
def completed_at_as_string(cls, v):
if not v:
return None
if isinstance(v, datetime):
return str(v.replace(tzinfo=timezone.utc))
if isinstance(v, str):
return v
return None


class NLGenerationResponse(BaseResponse):
sql_generation_id: str
Expand Down
2 changes: 1 addition & 1 deletion dataherald/db/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, system: System):
super().__init__(system)
db_uri = system.settings.require("db_uri")
db_name = system.settings.require("db_name")
self._data_store = MongoClient(db_uri)[db_name]
self._data_store = MongoClient(db_uri, tz_aware=True)[db_name]

@override
def find_one(self, collection: str, query: dict) -> dict:
Expand Down