A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Fixes a corrupted index not being handled by whoosh.create_in (#5950)
Trenton Hfba416e8e1d9
diff --git a/src/documents/index.py b/src/documents/index.pyindex de651c13d..b787c7635 100644--- a/src/documents/index.py+++ b/src/documents/index.py@@ -5,6 +5,7 @@ from collections import Counterfrom contextlib import contextmanagerfrom datetime import datetimefrom datetime import timezone+from shutil import rmtreefrom typing import Optionalfrom dateutil.parser import isoparse@@ -36,7 +37,6 @@ from whoosh.searching import Searcherfrom whoosh.util.times import timespanfrom whoosh.writing import AsyncWriter-# from documents.models import CustomMetadatafrom documents.models import CustomFieldInstancefrom documents.models import Documentfrom documents.models import Note@@ -87,8 +87,11 @@ def open_index(recreate=False) -> FileIndex:except Exception:logger.exception("Error while opening the index, recreating.")- if not os.path.isdir(settings.INDEX_DIR):- settings.INDEX_DIR.mkdir(parents=True, exist_ok=True)+ # create_in doesn't handle corrupted indexes very well, remove the directory entirely first+ if os.path.isdir(settings.INDEX_DIR):+ rmtree(settings.INDEX_DIR)+ settings.INDEX_DIR.mkdir(parents=True, exist_ok=True)+return create_in(settings.INDEX_DIR, get_schema())diff --git a/src/documents/tests/test_matchables.py b/src/documents/tests/test_matchables.pyindex 34bdffe95..4626e2c08 100644--- a/src/documents/tests/test_matchables.py+++ b/src/documents/tests/test_matchables.py@@ -1,6 +1,7 @@import shutilimport tempfilefrom collections.abc import Iterable+from pathlib import Pathfrom random import randintfrom django.contrib.admin.models import LogEntry@@ -396,7 +397,7 @@ class TestDocumentConsumptionFinishedSignal(TestCase):mime_type="application/pdf",)- self.index_dir = tempfile.mkdtemp()+ self.index_dir = Path(tempfile.mkdtemp())# TODO: we should not need the index here.override_settings(INDEX_DIR=self.index_dir).enable()