NYPL-Simplified / server_core

Shared data model and utilities for Library Simplified server applications
7 stars 11 forks source link

Convert datetimes on their way in and out of the database to avoid the need for a database migration. #1265

Closed leonardr closed 3 years ago

leonardr commented 3 years ago

This is a speculative branch that would allow us to release 4.0.0 (already a risky release due to the Python 3 migration) without also introducing a long-running database migration.

We've already done the work to make sure that all times go into the database as timezone-aware datetime objects. This branch modifies the DateTime database field type so that these values get converted into timezone-naive datetime objects at the last minute, on their way out to the database (converting to UTC if necessary), and then get converted into timezone-aware UTC objects on their way in from the database.

As far as I can tell, this works fine, but it introduces its own kind of risk, especially since I had to change the functions in datetime_helpers.py to return timezone-naive objects. I wouldn't think this would be necessary and it may indicate I have something wrong in the decorator class.

Given that we now only need to do one big 4.0.0 migration, based on code that's been thoroughly QAed, I'm leaning towards closing this PR, but I'd like to get your take first.