Przeglądaj źródła

Raise 404 with bulk actions for models which don't exist

Fixes #11491
Alex Tomkins 1 rok temu
rodzic
commit
f73ae8db90

+ 1 - 0
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)

+ 1 - 0
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

+ 12 - 0
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)

+ 4 - 1
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)