-
Notifications
You must be signed in to change notification settings - Fork 398
Open
Labels
Description
cms/cmscontrib/loaders/italy_yaml.py
Lines 127 to 131 in fcb70ee
| 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)