diff --git a/kolibri/core/content/api.py b/kolibri/core/content/api.py index 75ea57f6f4f..2fcc2799554 100644 --- a/kolibri/core/content/api.py +++ b/kolibri/core/content/api.py @@ -861,7 +861,7 @@ class ContentNodeViewset(InternalContentNodeMixin, RemoteMixin, ReadOnlyValuesVi def retrieve(self, request, pk=None): if pk is None: - raise Http404 + raise status.HTTP_400_BAD_REQUEST if self._should_proxy_request(request): if self.get_queryset().filter(admin_imported=True, pk=pk).exists(): # Used in the update method for remote request retrieval diff --git a/kolibri/core/content/public_api.py b/kolibri/core/content/public_api.py index 7b63db14f47..e6b4e141f98 100644 --- a/kolibri/core/content/public_api.py +++ b/kolibri/core/content/public_api.py @@ -3,6 +3,7 @@ from django.db import connection from django.db.models import Q from django.http import HttpResponseBadRequest +from rest_framework import status from rest_framework.response import Response from rest_framework.serializers import Serializer from rest_framework.viewsets import GenericViewSet @@ -50,6 +51,8 @@ def retrieve(self, request, pk=None): :param pk: id parent node :return: an object with keys for each content metadata table and a schema_version key """ + if pk is None: + raise status.HTTP_400_BAD_REQUEST content_schema = request.query_params.get( "schema_version", self.default_content_schema diff --git a/kolibri/core/content/test/test_content_app.py b/kolibri/core/content/test/test_content_app.py index 8154044443f..025f8d22b94 100644 --- a/kolibri/core/content/test/test_content_app.py +++ b/kolibri/core/content/test/test_content_app.py @@ -513,7 +513,7 @@ def test_contentnode_tree_bad_pk(self): kwargs={"pk": "this is not a UUID"}, ) ) - self.assertEqual(response.status_code, 404) + self.assertEqual(response.status_code, 400) @unittest.skipIf( getattr(settings, "DATABASES")["default"]["ENGINE"] diff --git a/kolibri/core/content/test/test_public_api.py b/kolibri/core/content/test/test_public_api.py index 790658d630c..b395a9882a5 100644 --- a/kolibri/core/content/test/test_public_api.py +++ b/kolibri/core/content/test/test_public_api.py @@ -95,6 +95,15 @@ def test_schema_version_too_high(self): ) self.assertEqual(response.status_code, 400) + def test_import_metadata_bad_pk(self): + response = self.client.get( + reverse( + "kolibri:core:importmetadata-detail", + kwargs={"pk": "this is not a UUID"}, + ) + ) + self.assertEqual(response.status_code, 400) + def test_schema_version_just_right(self): response = self.client.get( reverse("kolibri:core:importmetadata-detail", kwargs={"pk": self.node.id})