From 8960e237eac83529b9754e813c4901f5dd242e6f Mon Sep 17 00:00:00 2001 From: Stefan Hammer Date: Thu, 13 Jul 2023 10:21:38 +0200 Subject: [PATCH] Add upgrade considerations for the changed audit log timestamps See #9590 --- docs/releases/5.1.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/releases/5.1.md b/docs/releases/5.1.md index 313d9452d9cf..6dc4ea3f48a1 100644 --- a/docs/releases/5.1.md +++ b/docs/releases/5.1.md @@ -364,3 +364,17 @@ Additionally, two new events will be dispatched when the dialog visibility chang | ------ | ----------------- | | Show | `w-dialog:shown` | | Hide | `w-dialog:hidden` | + +### JSON-timestamps stored in `ModelLogEntry` and `PageLogEntry` are now ISO-formatted and UTC + +Previously, timestamps stored in the "data"-`JSONField` of `ModelLogEntry` and `PageLogEntry` have used the custom python format `%d %b %Y %H:%M`. Additionally, the `"go_live_at"` timestamp had been stored with the configured local timezone, instead of UTC. + +This has now been fixed, all timestamps are now stored as UTC, and because the "data"-`JSONField` now uses Django's `DjangoJSONEncoder`, those `datetime` objects are now automatically converted to the ISO format. This release contains a new migration `0088_fix_log_entry_json_timestamps` which converts all existing timestamps used by Wagtail to the new format. + +If you've developed your own subclasses of `ModelLogEntry`, `PageLogEntry` or `BaseLogEntry`, or used those existing models to create custom log entries, and you've stored timestamps similarly to Wagtail's old implementation (using `strftime("%d %b %Y %H:%M")`). You may want to adapt the storage of those timestamps to a consistent format too. + +There are probably three places in your code, which have to be changed: + +1. Creation: Instead of using `strftime("%d %b %Y %H:%M")`, you can now store the datetime directly in the "data" field. We've implemented a new helper `wagtail.utils.timestamps.ensure_utc()`, which ensures the correct timezone (UTC). +2. Display: To display the timestamp in the user's timezone and format with a `LogFormatter`, we've created utils to parse (`wagtail.utils.timestamps.parse_datetime_localized()`) and render (`wagtail.utils.timestamps.render_timestamp()`) those timestamps. Look at the existing formatters [here](https://github.com/wagtail/wagtail/blob/main/wagtail/wagtail_hooks.py). +3. Migration: You can use the code of the above migration ([source](https://github.com/wagtail/wagtail/blob/main/wagtail/migrations/0088_fix_log_entry_json_timestamps.py)) as a guideline to migrate your existing timestamps in the database.