cms-dev / cms-dev/cms

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

Open
#1,565 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
1k
Forks
412
Avg merge
6d 10h
Merged PRs (30d)
3

Description

https://github.com/cms-dev/cms/blob/fcb70eedc4552892f216606ca2864f4a130867d3/cmscontrib/loaders/italy_yaml.py#L127-L131

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read cmscontrib/loaders/italy_yaml.py at lines 127-131 and reproduce the importer with the server in a non-UTC timezone. Check how the resulting datetime is persisted through SQLAlchemy, then verify that imported timestamps retain the intended value without timezone-related conversion or warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlalchemy
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.