From 4e2efebaa724c7a7f5a728689fbda7cbbb8da619 Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Sun, 31 Jan 2021 13:20:21 +0100 Subject: [PATCH] addresses race condition between API and document consumer #472 --- src/documents/views.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/documents/views.py b/src/documents/views.py index 208f0fd07..f7c640e77 100755 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -398,19 +398,20 @@ class PostDocumentView(APIView): with tempfile.NamedTemporaryFile(prefix="paperless-upload-", dir=settings.SCRATCH_DIR, - buffering=0, delete=False) as f: f.write(doc_data) os.utime(f.name, times=(t, t)) + temp_filename = f.name + + async_task("documents.tasks.consume_file", + temp_filename, + override_filename=doc_name, + override_title=title, + override_correspondent_id=correspondent_id, + override_document_type_id=document_type_id, + override_tag_ids=tag_ids, + task_name=os.path.basename(doc_name)[:100]) - async_task("documents.tasks.consume_file", - f.name, - override_filename=doc_name, - override_title=title, - override_correspondent_id=correspondent_id, - override_document_type_id=document_type_id, - override_tag_ids=tag_ids, - task_name=os.path.basename(doc_name)[:100]) return Response("OK")