Skip to content

feat (JobDB): pydantic datetime validation #477

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 17 additions & 9 deletions diracx-core/src/diracx/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@

from __future__ import annotations

from datetime import datetime
from datetime import UTC, datetime
from enum import StrEnum
from typing import Literal

from pydantic import BaseModel, Field
from typing_extensions import TypedDict
from pydantic import AfterValidator, AwareDatetime, BaseModel, Field
from typing_extensions import Annotated, TypedDict


def good_utc_dt(v):
"""A validator that ensures that the aware datetime is in UTC timezone."""
return v.astimezone(UTC)


DiracUTCDatetime = Annotated[AwareDatetime, AfterValidator(good_utc_dt)]


class ScalarSearchOperator(StrEnum):
Expand Down Expand Up @@ -56,7 +64,7 @@ class InsertedJob(TypedDict):
JobID: int
Status: str
MinorStatus: str
TimeStamp: datetime
TimeStamp: DiracUTCDatetime


class JobSummaryParams(BaseModel):
Expand Down Expand Up @@ -101,7 +109,7 @@ class JobLoggingRecord(BaseModel):
status: JobStatus | Literal["idem"]
minor_status: str
application_status: str
date: datetime
date: DiracUTCDatetime
source: str


Expand Down Expand Up @@ -130,10 +138,10 @@ class SetJobStatusReturnSuccess(BaseModel):
Status: JobStatus | None = None
MinorStatus: str | None = None
ApplicationStatus: str | None = None
HeartBeatTime: datetime | None = None
StartExecTime: datetime | None = None
EndExecTime: datetime | None = None
LastUpdateTime: datetime | None = None
HeartBeatTime: DiracUTCDatetime | None = None
StartExecTime: DiracUTCDatetime | None = None
EndExecTime: DiracUTCDatetime | None = None
LastUpdateTime: DiracUTCDatetime | None = None

success: dict[int, SetJobStatusReturnSuccess]
failed: dict[int, dict[str, str]]
Expand Down
Loading