Fix: read zones before the consume transaction and write them before workflows

Zone OCR ran inside the consume transaction, read the working copy instead
of the archive, and ran after the document added workflows. Zones are now
read from the archive before the transaction and written just before
those workflows, keeping values supplied at consume time.
This commit is contained in:
stumpylog committed 2026-11-19 15:09:41 -08:00
1 parent 54be9dc9c5
commit a6b81b2d64
9 files changed
+1112 -164

No files matched your search

@@ -29,6 +29,8 @@ from documents.tasks import bulk_update_documents
from documents.zone_ocr import ZoneExtraction
from documents.zone_ocr import ZoneOcrReason
from documents.zone_ocr import ZoneOcrResult
from documents.zone_ocr import apply_zone_plans
from documents.zone_ocr import plan_zone_extraction
from paperless_testing.factories import CustomFieldFactory
from paperless_testing.factories import DocumentFactory
from paperless_testing.factories import OcrTemplateFactory
@@ -323,6 +325,14 @@ class TestZoneOcrIndexing:
)
with django_capture_on_commit_callbacks(execute=True):
if entry_point == "ingestion":
# The consumer writes the planned values, then sends the signal.
plans = plan_zone_extraction(
file_document.source_path,
file_document.page_count,
[template],
label="ingestion",
)
apply_zone_plans(document, plans, label="ingestion")
document_consumption_finished.send(sender=None, document=file_document)
elif entry_point == "single":
response = admin_client.post(