Ensure reindex happens after extraction on manual runs

This commit is contained in:
shamoon committed 2026-11-09 09:01:20 -08:00
1 parent 58cdd4f19a
commit 3ce5f8bc69
6 files changed
+110 -23

No files matched your search

+15 -15
View File
@@ -376,22 +376,22 @@ def extract_zones(document_id: int, template_id: int | None = None) -> None:
matches it when no template is given.
"""
document = Document.objects.get(id=document_id)
if template_id is None:
run_zone_extraction(document, None)
return
templates = None
if template_id is not None:
try:
template = OcrTemplate.objects.prefetch_related(
"zones",
"zones__custom_field",
).get(id=template_id)
except OcrTemplate.DoesNotExist:
logger.warning(
"OCR template %s no longer exists, not running zone OCR",
template_id,
)
return
templates = [template]
try:
template = OcrTemplate.objects.prefetch_related(
"zones",
"zones__custom_field",
).get(id=template_id)
except OcrTemplate.DoesNotExist:
logger.warning(
"OCR template %s no longer exists, not running zone OCR",
template_id,
)
return
run_zone_extraction(document, None, templates=[template])
run_zone_extraction(document, templates=templates, reindex=True)
@shared_task