From 039b2798fd6d54e5c62d5388dd9a9f34c58d86a9 Mon Sep 17 00:00:00 2001 From: Trenton Holmes <797416+stumpylog@users.noreply.github.com> Date: Sat, 2 May 2026 15:12:45 -0700 Subject: [PATCH] Trigger the celery task outside the atomic, if needed, so the DB is updated, in case the worker is racing to read it --- src/documents/bulk_edit.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/documents/bulk_edit.py b/src/documents/bulk_edit.py index 65ce3c785..ac89fb4d5 100644 --- a/src/documents/bulk_edit.py +++ b/src/documents/bulk_edit.py @@ -218,7 +218,7 @@ def modify_tags( doc_ids: list[int], add_tags: list[int], remove_tags: list[int], -) -> Literal["OK"]: +) -> Literal["OK"] | Literal["ERROR"]: qs = Document.objects.filter(id__in=doc_ids).only("pk") affected_docs = list(qs.values_list("pk", flat=True)) DocumentTagRelationship = Document.tags.through @@ -267,15 +267,16 @@ def modify_tags( ignore_conflicts=True, ) - if affected_docs: - bulk_update_documents.apply_async( - kwargs={"document_ids": affected_docs}, - headers={"trigger_source": PaperlessTask.TriggerSource.SYSTEM}, - ) except Exception as e: logger.error(f"Error modifying tags: {e}") return "ERROR" + if affected_docs: + bulk_update_documents.apply_async( + kwargs={"document_ids": affected_docs}, + headers={"trigger_source": PaperlessTask.TriggerSource.SYSTEM}, + ) + return "OK"