diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index 6f9e4a48f..eaf2cde83 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -1789,12 +1789,6 @@ class EditPdfDocumentsSerializer(DocumentListSerializer, SourceModeValidationMix "update_document only allowed with a single output document", ) - if any( - op.get("doc", 0) < 0 or op.get("doc", 0) >= len(operations) - for op in operations - ): - raise serializers.ValidationError("doc index is out of bounds") - doc = Document.objects.get(id=documents[0]) if doc.page_count: for op in operations: @@ -2159,12 +2153,6 @@ class BulkEditSerializer( "update_document only allowed with a single output document", ) - if any( - op.get("doc", 0) < 0 or op.get("doc", 0) >= len(parameters["operations"]) - for op in parameters["operations"] - ): - raise serializers.ValidationError("doc index is out of bounds") - doc = Document.objects.get(id=document_id) # doc existence is already validated if doc.page_count: diff --git a/src/documents/tests/test_api_bulk_edit.py b/src/documents/tests/test_api_bulk_edit.py index 436208d3a..59c872939 100644 --- a/src/documents/tests/test_api_bulk_edit.py +++ b/src/documents/tests/test_api_bulk_edit.py @@ -1769,7 +1769,14 @@ class TestBulkEditAPI(DirectoriesMixin, APITestCase): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertIn(b"valid integer is required", response.content) - for doc_index in (-1, 2**32): + # A negative doc index is rejected by PdfEditOperationSerializer's + # own min_value=0 field constraint, before the "doc index is out + # of bounds" object-level check (against len(operations)) ever + # runs -- hence the different expected message per case. + for doc_index, expected_message in ( + (-1, b"greater than or equal to 0"), + (2**32, b"doc index is out of bounds"), + ): with self.subTest(doc_index=doc_index): response = self.client.post( "/api/documents/edit_pdf/", @@ -1782,7 +1789,7 @@ class TestBulkEditAPI(DirectoriesMixin, APITestCase): content_type="application/json", ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - self.assertIn(b"doc index is out of bounds", response.content) + self.assertIn(expected_message, response.content) response = self.client.post( "/api/documents/edit_pdf/",