Skip to content

Commit

Permalink
API: make DateTimes timezone aware
Browse files Browse the repository at this point in the history
  • Loading branch information
carlinmack committed May 31, 2024
1 parent c7b8a36 commit f53b0d0
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions invenio_jobs/services/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
"""Service schemas."""

import inspect
from datetime import timezone

from invenio_i18n import lazy_gettext as _
from invenio_users_resources.services import schemas as user_schemas
from marshmallow import EXCLUDE, Schema, fields, validate
from marshmallow_oneofschema import OneOfSchema
from marshmallow_utils.fields import SanitizedUnicode
from marshmallow_utils.fields import SanitizedUnicode, TZDateTime
from marshmallow_utils.permissions import FieldPermissionsMixin
from marshmallow_utils.validators import LazyOneOf

Expand Down Expand Up @@ -114,8 +115,8 @@ class Meta:

id = fields.UUID(dump_only=True)

created = fields.DateTime(dump_only=True)
updated = fields.DateTime(dump_only=True)
created = TZDateTime(timezone=timezone.utc, format="iso", dump_only=True)
updated = TZDateTime(timezone=timezone.utc, format="iso", dump_only=True)

title = SanitizedUnicode(required=True, validate=_not_blank(max=250))
description = SanitizedUnicode()
Expand All @@ -130,7 +131,7 @@ class Meta:
validate=LazyOneOf(choices=lambda: current_jobs.queues.keys()),
load_default=lambda: current_jobs.default_queue,
)
default_args = fields.Dict(load_default=dict)
default_args = fields.Dict(load_default=dict, allow_none=True)

schedule = fields.Nested(ScheduleSchema, allow_none=True, load_default=None)

Expand Down Expand Up @@ -161,14 +162,14 @@ class Meta:
id = fields.UUID(dump_only=True)
job_id = fields.UUID(dump_only=True)

created = fields.DateTime(dump_only=True)
updated = fields.DateTime(dump_only=True)
created = TZDateTime(timezone=timezone.utc, format="iso", dump_only=True)
updated = TZDateTime(timezone=timezone.utc, format="iso", dump_only=True)

started_by_id = fields.Integer(dump_only=True)
started_by = fields.Nested(UserSchema, dump_only=True)

started_at = fields.DateTime(dump_only=True)
finished_at = fields.DateTime(dump_only=True)
started_at = TZDateTime(timezone=timezone.utc, format="iso", dump_only=True)
finished_at = TZDateTime(timezone=timezone.utc, format="iso", dump_only=True)

status = fields.Enum(RunStatusEnum, dump_only=True)
message = SanitizedUnicode(dump_only=True)
Expand Down

0 comments on commit f53b0d0

Please sign in to comment.