Skip to content

yaml importer uses incorrect timestamps when the server isn't in UTC #1565

@prandla

Description

@prandla

def parse_datetime(val):
if isinstance(val, datetime):
return val.astimezone(timezone.utc)
if isinstance(val, (int, float)):
return datetime.fromtimestamp(val, timezone.utc)

the yaml importer creates aware datetime objects with the timezone set to utc. sqlalchemy doesn't seem to enjoy these:

>>> import cms.db
>>> from datetime import datetime, timezone
>>> session = cms.db.Session()
>>> contest = cms.db.Contest.get_from_id(1, session)
>>> contest.start = datetime(2025, 9, 28, tzinfo=timezone.utc)
>>> contest.start
datetime.datetime(2025, 9, 28, 0, 0, tzinfo=datetime.timezone.utc)
>>> session.commit()
>>> contest.start
datetime.datetime(2025, 9, 28, 3, 0)

short term fix: we need to convert these aware datetimes to naive before passing them to sqlalchemy. longer term fix: we should probably be using aware datetimes instead... and possibly upgrading our sqlalchemy (it already throws warnings about deprecated datetime methods)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions