diff --git a/CHANGELOG.txt b/CHANGELOG.txt index f82ce97cc5..d45b6cbdad 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -9,6 +9,7 @@ Changelog * Fix: Ensure text only email notifications for updated comments do not escape HTML characters (Rohit Sharma) * Fix: Use logical OR operator to combine search fields for Django ORM in generic IndexView (Varun Kumar) * Fix: Ensure that explorer_results views fill in the correct next_url parameter on action URLs (Matt Westcott) + * Fix: Fix crash when accessing the history view for a translatable snippet (Sage Abdullah) * Docs: Fix code example for `{% picture ... as ... %}` template tag (Rezyapkin) diff --git a/docs/releases/5.2.1.md b/docs/releases/5.2.1.md index 450a787443..fcb711de8f 100644 --- a/docs/releases/5.2.1.md +++ b/docs/releases/5.2.1.md @@ -19,6 +19,7 @@ depth: 1 * Ensure text only email notifications for updated comments do not escape HTML characters (Rohit Sharma) * Use logical OR operator to combine search fields for Django ORM in generic IndexView (Varun Kumar) * Ensure that explorer_results views fill in the correct next_url parameter on action URLs (Matt Westcott) + * Fix crash when accessing the history view for a translatable snippet (Sage Abdullah) ### Documentation diff --git a/wagtail/admin/views/generic/models.py b/wagtail/admin/views/generic/models.py index 4c792c75fe..078a3f00c4 100644 --- a/wagtail/admin/views/generic/models.py +++ b/wagtail/admin/views/generic/models.py @@ -228,7 +228,10 @@ class IndexView( self.filters, queryset = self.filter_queryset(queryset) - if self.locale: + # Ensure the queryset is of the same model as self.model before filtering, + # which may not be the case for views like HistoryView where the queryset + # is of a LogEntry model for self.model. + if self.locale and queryset.model == self.model: queryset = queryset.filter(locale=self.locale) has_updated_at_column = any( diff --git a/wagtail/snippets/tests/test_snippets.py b/wagtail/snippets/tests/test_snippets.py index 26c44f4a78..2bce237aae 100644 --- a/wagtail/snippets/tests/test_snippets.py +++ b/wagtail/snippets/tests/test_snippets.py @@ -61,6 +61,7 @@ from wagtail.test.testapp.models import ( AdvertWithTabbedInterface, DraftStateCustomPrimaryKeyModel, DraftStateModel, + FullFeaturedSnippet, MultiPreviewModesModel, RevisableChildModel, RevisableModel, @@ -4117,10 +4118,10 @@ class TestSnippetHistory(WagtailTestUtils, TestCase): timestamp=make_aware(datetime.datetime(2022, 5, 10, 12, 34, 0)), object_id="1", ) - self.revisable_snippet = RevisableModel.objects.create(text="Foo") + self.revisable_snippet = FullFeaturedSnippet.objects.create(text="Foo") self.initial_revision = self.revisable_snippet.save_revision(user=self.user) ModelLogEntry.objects.create( - content_type=ContentType.objects.get_for_model(RevisableModel), + content_type=ContentType.objects.get_for_model(FullFeaturedSnippet), label="Foo", action="wagtail.create", timestamp=make_aware(datetime.datetime(2022, 5, 10, 20, 22, 0)), @@ -4227,6 +4228,8 @@ class TestSnippetHistory(WagtailTestUtils, TestCase): def test_get_with_i18n_enabled(self): response = self.get(self.non_revisable_snippet) self.assertEqual(response.status_code, 200) + response = self.get(self.revisable_snippet) + self.assertEqual(response.status_code, 200) class TestSnippetRevisions(WagtailTestUtils, TestCase):