فهرست منبع

Stop history view from breaking if a log entry's revision is missing (#12427)

e.g. after the purge_revisions management command has been run
Matt Westcott 5 ماه پیش
والد
کامیت
72fb0e9880
4فایلهای تغییر یافته به همراه25 افزوده شده و 0 حذف شده
  1. 1 0
      CHANGELOG.txt
  2. 1 0
      docs/releases/6.3.md
  3. 22 0
      wagtail/admin/tests/test_audit_log.py
  4. 1 0
      wagtail/admin/views/generic/history.py

+ 1 - 0
CHANGELOG.txt

@@ -153,6 +153,7 @@ Changelog
  * Fix: Fix focal point chooser when localization enabled (Sébastien Corbin)
  * Fix: Ensure that system checks for `WAGTAIL_DATE_FORMAT`, `WAGTAIL_DATETIME_FORMAT` and `WAGTAIL_TIME_FORMAT` take `FORMAT_MODULE_PATH` into account (Sébastien Corbin)
  * Fix: Prevent rich text fields inside choosers from being duplicated when opened repeatedly (Sage Abdullah)
+ * Fix: Prevent history view from breaking if a log entry's revision is missing (Matt Westcott)
  * Docs: Remove duplicate section on frontend caching proxies from performance page (Jake Howard)
  * Docs: Document `restriction_type` field on PageViewRestriction (Shlomo Markowitz)
  * Docs: Document Wagtail's bug bounty policy (Jake Howard)

+ 1 - 0
docs/releases/6.3.md

@@ -99,6 +99,7 @@ This feature was developed by Bart Cieliński, alexkiro, and Sage Abdullah.
  * Footer action buttons now include their `media` definitions (Sage Abdullah)
  * Improve the text contrast of the bulk actions "Select all" button (Sage Abdullah)
  * Fix error on workflow settings view with multiple snippet types assigned to the same workflow on Postgres (Sage Abdullah)
+ * Prevent history view from breaking if a log entry's revision is missing (Matt Westcott)
 
 ### Documentation
 

+ 22 - 0
wagtail/admin/tests/test_audit_log.py

@@ -1,7 +1,9 @@
 from datetime import timedelta
+from io import StringIO
 
 from django.conf import settings
 from django.contrib.auth.models import Group, Permission
+from django.core.management import call_command
 from django.test import TestCase
 from django.urls import reverse
 from django.utils import timezone
@@ -305,6 +307,26 @@ class TestAuditLogAdmin(AdminTemplateTestUtils, WagtailTestUtils, TestCase):
         response = self.client.get(reverse("wagtailadmin_reports:site_history"))
         self.assertContains(response, expected_deleted_string)
 
+    def test_page_history_after_revision_purge(self):
+        self._update_page(self.hello_page)
+        call_command("purge_revisions", days=0, stdout=StringIO())
+
+        history_url = reverse(
+            "wagtailadmin_pages:history", kwargs={"page_id": self.hello_page.id}
+        )
+
+        self.login(user=self.editor)
+
+        response = self.client.get(history_url)
+        self.assertEqual(response.status_code, 200)
+
+        self.assertContains(response, "Created", 1)
+        self.assertContains(response, "Draft saved", 2)
+        self.assertContains(response, "Locked", 1)
+        self.assertContains(response, "Unlocked", 1)
+        self.assertContains(response, "Page scheduled for publishing", 1)
+        self.assertContains(response, "Published", 1)
+
     def test_edit_form_has_history_link(self):
         self.hello_page.save_revision()
         self.login(user=self.editor)

+ 1 - 0
wagtail/admin/views/generic/history.py

@@ -165,6 +165,7 @@ class ActionColumn(Column):
 
         if (
             (url_name := self.url_names.get("revisions_unschedule"))
+            and instance.revision
             and instance.revision.approved_go_live_at
             and self.user_can_unschedule
         ):