Skip to content

Commit

Permalink
fix datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
giancarloromeo committed Nov 14, 2024
1 parent 5e69184 commit 3746196
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
14 changes: 0 additions & 14 deletions packages/common-library/src/common_library/pydantic_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,6 @@
from pydantic import TypeAdapter, field_validator


def validate_legacy_datetime_str(v: str | dt.datetime) -> dt.datetime:
if isinstance(v, dt.datetime):
return v
try:
return dt.datetime.fromisoformat(v)
except ValueError:
pass

try:
return dt.datetime.strptime(v, "%Y-%m-%d %H:%M:%S.%f%z")
except ValueError:
raise ValueError("Timestamp must be in a recognized datetime format")


def _validate_legacy_timedelta_str(time_str: str | dt.timedelta) -> str | dt.timedelta:
if not isinstance(time_str, str):
return time_str
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import datetime as dt
from contextlib import suppress
from typing import Annotated, Any
from typing import Any

from common_library.pydantic_validators import validate_legacy_datetime_str
from dask_task_models_library.container_tasks.protocol import ContainerEnvsDict
from models_library.api_schemas_directorv2.services import NodeRequirements
from models_library.basic_regex import SIMPLE_VERSION_RE
Expand All @@ -17,7 +16,6 @@
from models_library.services_resources import BootMode
from pydantic import (
BaseModel,
BeforeValidator,
ByteSize,
ConfigDict,
Field,
Expand Down Expand Up @@ -146,8 +144,8 @@ class CompTaskAtDB(BaseModel):
last_heartbeat: dt.datetime | None = Field(
..., description="Last time the running task was checked by the backend"
)
created: Annotated[dt.datetime, BeforeValidator(validate_legacy_datetime_str)]
modified: Annotated[dt.datetime, BeforeValidator(validate_legacy_datetime_str)]
created: dt.datetime
modified: dt.datetime
# Additional information about price and hardware (ex. AWS EC2 instance type)
pricing_info: dict | None
hardware_info: HardwareInfo
Expand Down Expand Up @@ -234,8 +232,8 @@ def to_db_model(self, **exclusion_rules) -> dict[str, Any]:
"state": "NOT_STARTED",
"progress": 0.44,
"last_heartbeat": None,
"created": "2022-05-20 13:28:31.139+00",
"modified": "2023-06-23 15:58:32.833081+00",
"created": "2022-05-20 13:28:31.139",
"modified": "2023-06-23 15:58:32.833081",
"pricing_info": {
"pricing_plan_id": 1,
"pricing_unit_id": 1,
Expand Down

0 comments on commit 3746196

Please sign in to comment.