diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 579e133ee5..4358492cf5 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -76,6 +76,7 @@ Changelog * Fix: Ensure `MultipleChooserPanel` modal works correctly when `USE_THOUSAND_SEPARATOR` is `True` for pages with ids over 1,000 (Sankalp, Rohit Sharma) * Fix: When using an empty table header (`th`) for visual spacing, ensure this is ignored by accessibility tooling (V Rohitansh) * Fix: Ensure the panel anchor button sizes meet accessibility guidelines for minimum dimensions (Nandini Arora) + * Fix: Raise a 404 for bulk actions for models which don't exist instead of throwing a 500 error (Alex Tomkins) * Docs: Document, for contributors, the use of translate string literals passed as arguments to tags and filters using `_()` within templates (Chiemezuo Akujobi) * Docs: Document all features for the Documents app in one location (Neeraj Yetheendran) * Docs: Add section to testing docs about creating pages and working with page content (Mariana Bedran Lesche) diff --git a/docs/releases/6.0.md b/docs/releases/6.0.md index 5bcbece751..932a3d65b7 100644 --- a/docs/releases/6.0.md +++ b/docs/releases/6.0.md @@ -109,6 +109,7 @@ Thank you to Thibaud Colas, Badr Fourane, and Sage Abdullah for their work on th * Ensure `MultipleChooserPanel` modal works correctly when `USE_THOUSAND_SEPARATOR` is `True` for pages with ids over 1,000 (Sankalp, Rohit Sharma) * When using an empty table header (`th`) for visual spacing, ensure this is ignored by accessibility tooling (V Rohitansh) * Ensure the panel anchor button sizes meet accessibility guidelines for minimum dimensions (Nandini Arora) + * Raise a 404 for bulk actions for models which don't exist instead of throwing a 500 error (Alex Tomkins) ### Documentation diff --git a/wagtail/admin/tests/pages/test_bulk_actions/test_bulk_action.py b/wagtail/admin/tests/pages/test_bulk_actions/test_bulk_action.py index 84621f4759..ead9750f69 100644 --- a/wagtail/admin/tests/pages/test_bulk_actions/test_bulk_action.py +++ b/wagtail/admin/tests/pages/test_bulk_actions/test_bulk_action.py @@ -20,3 +20,15 @@ class TestBulkActionDispatcher(WagtailTestUtils, TestCase): ) response = self.client.get(url) self.assertEqual(response.status_code, 404) + + def test_bulk_action_invalid_model(self): + url = reverse( + "wagtail_bulk_action", + args=( + "doesnotexist", + "doesnotexist", + "doesnotexist", + ), + ) + response = self.client.get(url) + self.assertEqual(response.status_code, 404) diff --git a/wagtail/admin/views/bulk_action/dispatcher.py b/wagtail/admin/views/bulk_action/dispatcher.py index 718bc0af9d..ef2ad5e3e6 100644 --- a/wagtail/admin/views/bulk_action/dispatcher.py +++ b/wagtail/admin/views/bulk_action/dispatcher.py @@ -5,7 +5,10 @@ from wagtail.admin.views.bulk_action.registry import bulk_action_registry as reg def index(request, app_label, model_name, action): - model = apps.get_model(app_label, model_name) + try: + model = apps.get_model(app_label, model_name) + except LookupError: + raise Http404 action_class = registry.get_bulk_action_class(app_label, model_name, action) if action_class is not None: return action_class(request, model).dispatch(request)