From 0348dc532f430d418e6f746fd29f674c809d9612 Mon Sep 17 00:00:00 2001 From: stumpylog <797416+stumpylog@users.noreply.github.com> Date: Fri, 20 Nov 2026 09:38:50 -0800 Subject: [PATCH] Fix: create the scratch dir before zone OCR renders into it --- src/documents/views.py | 1 + src/documents/zone_ocr.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/documents/views.py b/src/documents/views.py index cd40338fc0..592702170e 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -5926,6 +5926,7 @@ class OcrTemplateViewSet(BulkPermissionMixin, PassUserMixin, ModelViewSet[OcrTem content_type=file_doc.mime_type, ) + settings.SCRATCH_DIR.mkdir(parents=True, exist_ok=True) with tempfile.TemporaryDirectory(dir=settings.SCRATCH_DIR) as tmp_dir: rendered = Path(tmp_dir) / "page.png" try: diff --git a/src/documents/zone_ocr.py b/src/documents/zone_ocr.py index 42663b4327..b05cb837a9 100644 --- a/src/documents/zone_ocr.py +++ b/src/documents/zone_ocr.py @@ -339,6 +339,7 @@ def plan_zone_extraction( if not pages: return [] plans = [] + settings.SCRATCH_DIR.mkdir(parents=True, exist_ok=True) with tempfile.TemporaryDirectory(dir=settings.SCRATCH_DIR) as tmp_dir: tmp_path = Path(tmp_dir) page_images = _render_pages( @@ -849,6 +850,7 @@ def extract_zone_preview( ) -> ZoneExtraction: """Extract a zone without writing its value to the document.""" page_idx = _resolve_page_idx(zone.page, page_count) + settings.SCRATCH_DIR.mkdir(parents=True, exist_ok=True) with tempfile.TemporaryDirectory(dir=settings.SCRATCH_DIR) as tmp_dir: tmp_path = Path(tmp_dir) page_images = _render_pages(