Trigger the celery task outside the atomic, if needed, so the DB is updated, in case the worker is racing to read it

This commit is contained in:
Trenton Holmes
2026-05-02 15:12:45 -07:00
parent 37496775c0
commit 039b2798fd
+7 -6
View File
@@ -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"