Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Lock the media directory and refresh the document to ensure we have where it actually lives before attaching (#8737)

Trenton H49a96ccee0be
diff --git a/src/documents/signals/handlers.py b/src/documents/signals/handlers.py
index d3fa11b3b..c836f4d1e 100644
--- a/src/documents/signals/handlers.py
+++ b/src/documents/signals/handlers.py
@@ -943,7 +943,10 @@ def run_workflows(
to=action.email.to.split(","),
)
if action.email.include_document:
- email.attach_file(document.source_path)
+ # Something could be renaming the file concurrently so it can't be attached
+ with FileLock(settings.MEDIA_LOCK):
+ document.refresh_from_db()
+ email.attach_file(document.source_path)
n_messages = email.send()
logger.debug(
f"Sent {n_messages} notification email(s) to {action.email.to}",