Skip to content

Commit

Permalink
Fix crash when accessing the history view for a translatable snippet
Browse files Browse the repository at this point in the history
Regression in dc049cd.
  • Loading branch information
laymonage committed Nov 9, 2023
1 parent 771e838 commit 2d5dc4d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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)


Expand Down
1 change: 1 addition & 0 deletions docs/releases/5.2.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion wagtail/admin/views/generic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ def get_queryset(self):

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(
Expand Down
7 changes: 5 additions & 2 deletions wagtail/snippets/tests/test_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
AdvertWithTabbedInterface,
DraftStateCustomPrimaryKeyModel,
DraftStateModel,
FullFeaturedSnippet,
MultiPreviewModesModel,
RevisableChildModel,
RevisableModel,
Expand Down Expand Up @@ -4117,10 +4118,10 @@ def setUp(self):
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)),
Expand Down Expand Up @@ -4227,6 +4228,8 @@ def test_with_live_and_draft_status(self):
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):
Expand Down

0 comments on commit 2d5dc4d

Please sign in to comment.