Repository: paperless-ngx/paperless-ngx

Issue:
[BUG] PAPERLESS_OCR_MODE=skip_noarchive not adhered when storage path is set to automatic
### Description

Paperless 1.8.0
Docker 20.10.17
Debian 11

Variable 
PAPERLESS_OCR_MODE=skip_noarchive is set and available in docker session
(tested with - echo $PAPERLESS_OCR_MODE

If storage path is set eg:
{correspondent}/{created_day}_{created_month}_{created_year}_{title}
Mode: Find Any word: "foo" "foo bar"

archive files are not created - GOOD! as variable skip_noarchive is set

If storage path is set eg:
{correspondent}/{created_day}_{created_month}_{created_year}_{title}
Mode: AUTO

archive files are created - BAD! as variable skip_noarchive is set



### Steps to reproduce

1. set variable PAPERLESS_OCR_MODE=skip_noarchive
2. check if available in docker
3. configure storage path with find any term condition
4. consume a pdf
5. archive file is not created
6. configure storage path with AUTO condition
7. consume a pdf
8. archive file will be created

### Webserver logs

_No response_

### Paperless-ngx version

1.8.0

### Host OS

Debian 11

### Installation method

Docker - official image

### Browser

Chrome

### Configuration changes

_No response_

### Other

_No response_


Discussion:
There's definitely something going on with `skip_noarchive` mode.  Not 100% sure it is related to storage paths as I can see archive files generated when none exist.

At a guess, it's when the file doesn't have existing text on some pages, so OCR is still preformed, and there's no check against creating an archive file at that point.

Resolving patch:
diff --git a/src/paperless_tesseract/parsers.py b/src/paperless_tesseract/parsers.py
--- a/src/paperless_tesseract/parsers.py
+++ b/src/paperless_tesseract/parsers.py
@@ -276,7 +276,10 @@ def parse(self, document_path, mime_type, file_name=None):
             self.log("debug", f"Calling OCRmyPDF with args: {args}")
             ocrmypdf.ocr(**args)
 
-            self.archive_path = archive_path
+            # Only create archive file if archiving isn't being skipped
+            if settings.OCR_MODE != "skip_noarchive":
+                self.archive_path = archive_path
+
             self.text = self.extract_text(sidecar_file, archive_path)
 
             if not self.text:


Test patch:
diff --git a/src/paperless_tesseract/tests/test_parser.py b/src/paperless_tesseract/tests/test_parser.py
--- a/src/paperless_tesseract/tests/test_parser.py
+++ b/src/paperless_tesseract/tests/test_parser.py
@@ -364,6 +364,16 @@ def test_multi_page_analog_pages_force(self):
 
     @override_settings(OCR_MODE="skip_noarchive")
     def test_skip_noarchive_withtext(self):
+        """
+        GIVEN:
+            - File with existing text layer
+            - OCR mode set to skip_noarchive
+        WHEN:
+            - Document is parsed
+        THEN:
+            - Text from images is extracted
+            - No archive file is created
+        """
         parser = RasterisedDocumentParser(None)
         parser.parse(
             os.path.join(self.SAMPLE_FILES, "multi-page-digital.pdf"),
@@ -377,17 +387,29 @@ def test_skip_noarchive_withtext(self):
 
     @override_settings(OCR_MODE="skip_noarchive")
     def test_skip_noarchive_notext(self):
+        """
+        GIVEN:
+            - File with text contained in images but no text layer
+            - OCR mode set to skip_noarchive
+        WHEN:
+            - Document is parsed
+        THEN:
+            - Text from images is extracted
+            - No archive file is created
+        """
         parser = RasterisedDocumentParser(None)
         parser.parse(
             os.path.join(self.SAMPLE_FILES, "multi-page-images.pdf"),
             "application/pdf",
         )
-        self.assertTrue(os.path.isfile(parser.archive_path))
+
         self.assertContainsStrings(
             parser.get_text().lower(),
             ["page 1", "page 2", "page 3"],
         )
 
+        self.assertIsNone(parser.archive_path)
+
     @override_settings(OCR_MODE="skip")
     def test_multi_page_mixed(self):
         parser = RasterisedDocumentParser(None)
@@ -408,6 +430,16 @@ def test_multi_page_mixed(self):
 
     @override_settings(OCR_MODE="skip_noarchive")
     def test_multi_page_mixed_no_archive(self):
+        """
+        GIVEN:
+            - File with some text contained in images and some in text layer
+            - OCR mode set to skip_noarchive
+        WHEN:
+            - Document is parsed
+        THEN:
+            - Text from images is extracted
+            - No archive file is created
+        """
         parser = RasterisedDocumentParser(None)
         parser.parse(
             os.path.join(self.SAMPLE_FILES, "multi-page-mixed.pdf"),