Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timezone consistency across deployments & UI #970

Merged
merged 3 commits into from
Nov 4, 2024
Merged

Conversation

ml-evs
Copy link
Member

@ml-evs ml-evs commented Oct 26, 2024

This PR enforces UTC for all datetimes stored by datalab, via:

  • updating the underlying model so that any missing timezone from a user/script is interpreted as UTC. This is done at the validator level, so some inconsistencies might arise in old data that has not previously been stored with a timezone, but the API at least will always validate and fix it this now. I explicitly added the timezones into remote fs checking so that we don't have to worry about mongo version compatibility.
  • The app code can now assume that a missing timezone really does mean UTC, and all future timestamps should have the 00:00 UTC offset suffix.
  • App code now has to have a custom computed setter/getter for datetime objects, so that we can cast the format from HTML <input format='datetime-local'> into the full isoformat stamp.
  • all internal datetimes now use UTC explicitly, with enabling of the ruff DTZ/flake8-datetimez linting rules

Closes #440

Assorted fixes:

  • the IsoformatDateTime wrapper was also setting a bad JSON Schema type, for some reason -- this is removed
  • The File model wasn't using the extended datetime format for time_added.

Relatedly (from HN today...): https://ssoready.com/blog/engineering/truths-programmers-timezones/

Copy link

cypress bot commented Oct 26, 2024

datalab    Run #2712

Run Properties:  status check passed Passed #2712  •  git commit 0cfa8498f3 ℹ️: Merge 606408e076347421c96b8f2ff746892d45c08469 into 509f04f3d194eb7838060905df07...
Project datalab
Branch Review ml-evs/datetime-fixes
Run status status check passed Passed #2712
Run duration 06m 11s
Commit git commit 0cfa8498f3 ℹ️: Merge 606408e076347421c96b8f2ff746892d45c08469 into 509f04f3d194eb7838060905df07...
Committer Matthew Evans
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 405
View all changes introduced in this branch ↗︎

@ml-evs ml-evs force-pushed the ml-evs/datetime-fixes branch 2 times, most recently from 5493a64 to f29eae3 Compare October 26, 2024 17:19
@ml-evs ml-evs marked this pull request as ready for review October 26, 2024 17:19
Copy link

codecov bot commented Oct 26, 2024

Codecov Report

Attention: Patch coverage is 74.07407% with 7 lines in your changes missing coverage. Please review.

Project coverage is 68.43%. Comparing base (509f04f) to head (618290c).

Files with missing lines Patch % Lines
pydatalab/src/pydatalab/file_utils.py 28.57% 5 Missing ⚠️
pydatalab/src/pydatalab/remote_filesystems.py 87.50% 1 Missing ⚠️
pydatalab/src/pydatalab/routes/v0_1/collections.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #970      +/-   ##
==========================================
+ Coverage   68.42%   68.43%   +0.01%     
==========================================
  Files          62       62              
  Lines        3933     3935       +2     
==========================================
+ Hits         2691     2693       +2     
  Misses       1242     1242              
Files with missing lines Coverage Δ
pydatalab/src/pydatalab/backups.py 48.59% <100.00%> (ø)
pydatalab/src/pydatalab/models/files.py 100.00% <100.00%> (ø)
pydatalab/src/pydatalab/models/utils.py 87.57% <100.00%> (-0.08%) ⬇️
pydatalab/src/pydatalab/routes/v0_1/auth.py 63.54% <100.00%> (ø)
pydatalab/src/pydatalab/routes/v0_1/items.py 82.65% <100.00%> (ø)
pydatalab/src/pydatalab/remote_filesystems.py 79.74% <87.50%> (+0.52%) ⬆️
pydatalab/src/pydatalab/routes/v0_1/collections.py 70.45% <50.00%> (ø)
pydatalab/src/pydatalab/file_utils.py 38.83% <28.57%> (ø)

@ml-evs ml-evs force-pushed the ml-evs/datetime-fixes branch from f29eae3 to f7cd422 Compare October 26, 2024 17:33
@ml-evs ml-evs added API For issues/PRs pertaining to the API webapp For issues/PRs pertaining to the web interface usability labels Oct 26, 2024
@ml-evs ml-evs added this to the v0.5.x milestone Oct 26, 2024
@ml-evs ml-evs force-pushed the ml-evs/datetime-fixes branch from f7cd422 to 853f82d Compare October 26, 2024 17:41
Copy link
Member Author

@ml-evs ml-evs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should fix the issue you were seeing @BenjaminCharmes, was just some overzealous refactoring

@ml-evs ml-evs changed the title Add timezone consistency across deployments Add timezone consistency across deployments & UI Oct 29, 2024
@ml-evs ml-evs force-pushed the ml-evs/datetime-fixes branch 3 times, most recently from dd330e6 to 618290c Compare November 3, 2024 16:39
- Enable DTZ (flake8-datetimez) rules in ruff

- Update test cases to use tz where needed

- Add any missing timezone info when remote filesystem syncing
- Update custom datetime to add any missing timezone

- Fix: datetime wrapper should not make up a new JSONSchema type

- Use extended datetime for `time_added` in `File` model
Remove now-unnecessary timezone workaround in app

Update app test with UTC offset

Fix app bug introduced during refactor

Add specific handling of datetime fields in computed getters/setters

Use localized timestamp in UI, thanks to Sweden

Fix UI date display when updated in starting_materials EditPage
@ml-evs ml-evs force-pushed the ml-evs/datetime-fixes branch from 618290c to 606408e Compare November 4, 2024 18:10
@ml-evs ml-evs merged commit fc2cf1b into main Nov 4, 2024
15 checks passed
@ml-evs ml-evs deleted the ml-evs/datetime-fixes branch November 4, 2024 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API For issues/PRs pertaining to the API usability webapp For issues/PRs pertaining to the web interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Server last_modified times depend on server timezone
1 participant