mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-11 09:14:02 -04:00
Raise exceptions instead of returning error strings in edit_pdf
This commit is contained in:
parent
92b9c69806
commit
232f13f69b
@ -532,7 +532,7 @@ def edit_pdf(
|
|||||||
logger.error(
|
logger.error(
|
||||||
"Update requested but multiple output documents specified",
|
"Update requested but multiple output documents specified",
|
||||||
)
|
)
|
||||||
return "ERROR"
|
raise ValueError("Multiple output documents specified")
|
||||||
|
|
||||||
for op in operations:
|
for op in operations:
|
||||||
dst = pdf_docs[op.get("doc", 0)]
|
dst = pdf_docs[op.get("doc", 0)]
|
||||||
@ -583,7 +583,9 @@ def edit_pdf(
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(f"Error editing document {doc.id}: {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"
|
return "OK"
|
||||||
|
|
||||||
|
@ -1032,8 +1032,8 @@ class TestPDFActions(DirectoriesMixin, TestCase):
|
|||||||
{"page": 9999}, # invalid page, forces error during PDF load
|
{"page": 9999}, # invalid page, forces error during PDF load
|
||||||
]
|
]
|
||||||
with self.assertLogs("paperless.bulk_edit", level="ERROR"):
|
with self.assertLogs("paperless.bulk_edit", level="ERROR"):
|
||||||
result = bulk_edit.edit_pdf(doc_ids, operations)
|
with self.assertRaises(Exception):
|
||||||
self.assertEqual(result, "ERROR")
|
bulk_edit.edit_pdf(doc_ids, operations)
|
||||||
mock_group.assert_not_called()
|
mock_group.assert_not_called()
|
||||||
mock_consume_file.assert_not_called()
|
mock_consume_file.assert_not_called()
|
||||||
|
|
||||||
@ -1058,7 +1058,7 @@ class TestPDFActions(DirectoriesMixin, TestCase):
|
|||||||
{"page": 2, "doc": 1},
|
{"page": 2, "doc": 1},
|
||||||
]
|
]
|
||||||
with self.assertLogs("paperless.bulk_edit", level="ERROR"):
|
with self.assertLogs("paperless.bulk_edit", level="ERROR"):
|
||||||
result = bulk_edit.edit_pdf(doc_ids, operations, update_document=True)
|
with self.assertRaises(ValueError):
|
||||||
self.assertEqual(result, "ERROR")
|
bulk_edit.edit_pdf(doc_ids, operations, update_document=True)
|
||||||
mock_group.assert_not_called()
|
mock_group.assert_not_called()
|
||||||
mock_consume_file.assert_not_called()
|
mock_consume_file.assert_not_called()
|
||||||
|
@ -1427,7 +1427,6 @@ class BulkEditView(PassUserMixin):
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO: parameter validation
|
|
||||||
result = method(documents, **parameters)
|
result = method(documents, **parameters)
|
||||||
|
|
||||||
if settings.AUDIT_LOG_ENABLED and modified_field:
|
if settings.AUDIT_LOG_ENABLED and modified_field:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user