mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-18 17:34:39 -05:00
Compare commits
5 Commits
24f6766bb7
...
056b314a89
Author | SHA1 | Date | |
---|---|---|---|
![]() |
056b314a89 | ||
![]() |
ba91bb154a | ||
![]() |
3c4225979e | ||
![]() |
84b5ef7c34 | ||
![]() |
d579caf1ea |
@ -468,7 +468,7 @@ class ConsumerPlugin(
|
|||||||
# now that everything is done, we can start to store the document
|
# now that everything is done, we can start to store the document
|
||||||
# in the system. This will be a transaction and reasonably fast.
|
# in the system. This will be a transaction and reasonably fast.
|
||||||
success = False
|
success = False
|
||||||
result = None
|
store_exception = None
|
||||||
try:
|
try:
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
# store the document.
|
# store the document.
|
||||||
@ -535,18 +535,8 @@ class ConsumerPlugin(
|
|||||||
document.save()
|
document.save()
|
||||||
success = True
|
success = True
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
# save the exception for later
|
|
||||||
try:
|
|
||||||
self._fail(
|
|
||||||
str(e),
|
|
||||||
f"The following error occurred while storing document "
|
|
||||||
f"{self.filename} after parsing: {e}",
|
|
||||||
exc_info=True,
|
|
||||||
exception=e,
|
|
||||||
)
|
|
||||||
except Exception as fail_exc:
|
except Exception as fail_exc:
|
||||||
stored_exception = fail_exc
|
store_exception = fail_exc
|
||||||
finally:
|
finally:
|
||||||
if success:
|
if success:
|
||||||
# Delete the file only if it was successfully consumed
|
# Delete the file only if it was successfully consumed
|
||||||
@ -581,19 +571,26 @@ class ConsumerPlugin(
|
|||||||
# Return the most up to date fields
|
# Return the most up to date fields
|
||||||
document.refresh_from_db()
|
document.refresh_from_db()
|
||||||
|
|
||||||
result = f"Success. New document id {document.pk} created"
|
document_parser.cleanup()
|
||||||
elif stored_exception:
|
tempdir.cleanup()
|
||||||
raise stored_exception
|
return f"Success. New document id {document.pk} created"
|
||||||
|
else:
|
||||||
|
document_parser.cleanup()
|
||||||
|
tempdir.cleanup()
|
||||||
|
if store_exception:
|
||||||
|
self._fail(
|
||||||
|
str(store_exception),
|
||||||
|
f"The following error occurred while storing document "
|
||||||
|
f"{self.filename} after parsing: {store_exception}",
|
||||||
|
exc_info=True,
|
||||||
|
exception=store_exception,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self._fail(
|
self._fail(
|
||||||
ConsumerStatusShortMessage.FAILED,
|
ConsumerStatusShortMessage.FAILED,
|
||||||
f"Error occurred while saving {self.filename}.",
|
f"Error occurred while saving {self.filename}.",
|
||||||
)
|
)
|
||||||
|
|
||||||
document_parser.cleanup()
|
|
||||||
tempdir.cleanup()
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _parse_title_placeholders(self, title: str) -> str:
|
def _parse_title_placeholders(self, title: str) -> str:
|
||||||
local_added = timezone.localtime(timezone.now())
|
local_added = timezone.localtime(timezone.now())
|
||||||
|
|
||||||
|
@ -636,16 +636,9 @@ class TestConsumer(
|
|||||||
@mock.patch("documents.consumer.ConsumerPlugin._store")
|
@mock.patch("documents.consumer.ConsumerPlugin._store")
|
||||||
@mock.patch("documents.consumer.document_consumption_finished.send")
|
@mock.patch("documents.consumer.document_consumption_finished.send")
|
||||||
@mock.patch("documents.consumer.generate_unique_filename")
|
@mock.patch("documents.consumer.generate_unique_filename")
|
||||||
def test_post_consume_fails_silently(self, m_filename, m_signal, m_store):
|
def testSaveFailsStillCaught(self, m_filename, m_signal, m_store):
|
||||||
"""
|
|
||||||
If _store() returns None but no exception is raised, _fail should still be called.
|
|
||||||
"""
|
|
||||||
filename = self.get_test_file()
|
filename = self.get_test_file()
|
||||||
|
|
||||||
# Make _store() return None
|
|
||||||
m_store.return_value = None
|
m_store.return_value = None
|
||||||
|
|
||||||
# Cause crash in a predictable, testable place
|
|
||||||
m_filename.side_effect = AttributeError("BOOM")
|
m_filename.side_effect = AttributeError("BOOM")
|
||||||
|
|
||||||
with self.get_consumer(filename) as consumer:
|
with self.get_consumer(filename) as consumer:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user