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

Use timezone aware timestamps for file modification #1992

Merged
merged 3 commits into from
Sep 25, 2024

Conversation

replaceafill
Copy link
Member

@replaceafill replaceafill commented Sep 18, 2024

This updates the Store file modification dates MCPClient job to store transfer file modification dates using the TIME_ZONE setting from Django.

Currently the server logs show that these values are naive:

Sep 13 11:11:03 am116jammy python[705915]: *** RUNNING TASK: storefilemodificationdates_v0.0***
Sep 13 11:11:03 am116jammy python[705915]: /usr/share/archivematica/virtualenvs/archivematica/lib/python3.9/site-packages/django/db/models/fields/__init__.py:1595: RuntimeWarning: DateTimeField File.modifi
cationtime received a naive datetime (2024-04-03 07:02:29) while time zone support is active.
Sep 13 11:11:03 am116jammy python[705915]:   warnings.warn(
Sep 13 11:11:03 am116jammy python[705915]: archivematicaClient.py: INFO      2024-09-13 04:11:03,101  archivematica.mcp.client.storeFileModificationDates:main:64:  Stored modification dates of 2 files.
Sep 13 11:11:03 am116jammy python[705915]: archivematicaClient.py: INFO      2024-09-13 04:11:03,102  archivematica.mcp.client.job:log_results:82:  #<storefilemodificationdates_v0.0; exit=0; code=success u
uid=e7ea9514-444b-469c-9eee-561aba85b3ad

This could potentially create problems. Recently an Archivematica 1.15.x user reported pytz raising a NonExistentTimeError because of this in Django 3.2.

This test case represents a time zone and file modification time
combination that makes the job to fail in Archivematica 1.15.x.

In this commit the test fails because the expected time is now time
zone aware but the job has not been updated to use the current time
zone yet.

```console
FAILED test_store_file_modification.py::TestStoreFileModification::test_store_file_modification_dates - AssertionError: assert '2003-04-06 07:59:30+00:00' == '2003-04-06 02:59:30+00:00'

  - 2003-04-06 02:59:30+00:00
  ?             ^
  + 2003-04-06 07:59:30+00:00
  ?             ^
```
@replaceafill replaceafill requested a review from a team September 18, 2024 18:23
Copy link
Contributor

@Dhwaniartefact Dhwaniartefact left a comment

Choose a reason for hiding this comment

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

LGTM !

@replaceafill replaceafill merged commit 3374c34 into qa/1.x Sep 25, 2024
26 checks passed
@replaceafill replaceafill deleted the dev/fix-store-file-modification-dates branch September 25, 2024 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants