From 34f2385df4a1bb929c41dd256e0d296d3bc1e99f Mon Sep 17 00:00:00 2001 From: Trenton Holmes <797416+stumpylog@users.noreply.github.com> Date: Sun, 13 Sep 2026 15:06:52 -0700 Subject: [PATCH] Fix: resolve silent duplication from rebase onto fix/bulk_edit Rebasing onto origin/fix/bulk_edit (PR #14083, which independently bounds the edit_pdf doc index via manual checks) applied cleanly with no reported conflicts, but left two copies of the same "doc index is out of bounds" check back to back in both EditPdfDocumentsSerializer .validate and BulkEditSerializer._validate_parameters_edit_pdf -- #14083's own `< 0 or >= len(operations)` check is now fully redundant here since PdfEditOperationSerializer.doc already has min_value=0. Removed the redundant second check in both methods. Also split the merged test_edit_pdf_invalid_params subtest: #14083's loop asserted the same "doc index is out of bounds" message for both doc=-1 and doc=2**32, but with min_value=0 in place, -1 is now rejected earlier by the field itself with a different message. --- src/documents/serialisers.py | 12 ------------ src/documents/tests/test_api_bulk_edit.py | 11 +++++++++-- 2 files changed, 9 insertions(+), 14 deletions(-) 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/",