]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Raise exceptions instead of returning error strings in edit_pdf
authorshamoon <4887959+shamoon@users.noreply.github.com>
Sat, 2 Aug 2025 13:43:49 +0000 (09:43 -0400)
committershamoon <4887959+shamoon@users.noreply.github.com>
Sat, 2 Aug 2025 13:43:49 +0000 (09:43 -0400)
src/documents/bulk_edit.py
src/documents/tests/test_bulk_edit.py
src/documents/views.py

index af6be45b69cf7c95e358cbe25d4c885df6a1dbf5..8ef807da8507440ad6c8ab432d9e3a8d679352d1 100644 (file)
@@ -532,7 +532,7 @@ def edit_pdf(
                 logger.error(
                     "Update requested but multiple output documents specified",
                 )
-                return "ERROR"
+                raise ValueError("Multiple output documents specified")
 
             for op in operations:
                 dst = pdf_docs[op.get("doc", 0)]
@@ -583,7 +583,9 @@ def edit_pdf(
 
     except Exception as e:
         logger.exception(f"Error editing document {doc.id}: {e}")
-        return "ERROR"
+        raise ValueError(
+            f"An error occurred while editing the document: {e}",
+        ) from e
 
     return "OK"
 
index 8af641ed4d72d3133bd43567dd1c3ad5b478b7a3..4e6200719686de208a9e3d2a177488fb462fc2ff 100644 (file)
@@ -1032,8 +1032,8 @@ class TestPDFActions(DirectoriesMixin, TestCase):
             {"page": 9999},  # invalid page, forces error during PDF load
         ]
         with self.assertLogs("paperless.bulk_edit", level="ERROR"):
-            result = bulk_edit.edit_pdf(doc_ids, operations)
-            self.assertEqual(result, "ERROR")
+            with self.assertRaises(Exception):
+                bulk_edit.edit_pdf(doc_ids, operations)
         mock_group.assert_not_called()
         mock_consume_file.assert_not_called()
 
@@ -1058,7 +1058,7 @@ class TestPDFActions(DirectoriesMixin, TestCase):
             {"page": 2, "doc": 1},
         ]
         with self.assertLogs("paperless.bulk_edit", level="ERROR"):
-            result = bulk_edit.edit_pdf(doc_ids, operations, update_document=True)
-            self.assertEqual(result, "ERROR")
+            with self.assertRaises(ValueError):
+                bulk_edit.edit_pdf(doc_ids, operations, update_document=True)
         mock_group.assert_not_called()
         mock_consume_file.assert_not_called()
index 6c9ce38dd0f1d80b9a6e6396b8f3346dd0aa6ccf..c98df6da4d70195462b526725245ea191af548dc 100644 (file)
@@ -1427,7 +1427,6 @@ class BulkEditView(PassUserMixin):
                     )
                 }
 
-            # TODO: parameter validation
             result = method(documents, **parameters)
 
             if settings.AUDIT_LOG_ENABLED and modified_field: