Repository: paperless-ngx/paperless-ngx

Issue:
[BUG] Consume PDF settings broken regaring environment variable config
### Description

Seems like changes broke the previous environment settings compatibility of v2.2.1 to 2.3.0:

Partial doker-compose yml:
```yml
###############################################################################
# Paperless-specific settings                                                 #
###############################################################################

      PAPERLESS_URL: $URL
      PAPERLESS_WEBSERVER_WORKERS: 1
      PAPERLESS_BIND_ADDR: "[::]"
      PAPERLESS_PORT: 8000
      PAPERLESS_ALLOWED_HOSTS: "$URL,$LOCALIP,$HOSTNAME,localhost"
      PAPERLESS_CSRF_TRUSTED_ORIGINS: "$URL,http://$LOCALIP:8000,http://$HOSTNAME:8000,http://localhost:8000"
      PAPERLESS_CORS_ALLOWED_HOSTS: "$URL,http://$LOCALIP:8000,http://$HOSTNAME:8000,http://localhost:8000"
      PAPERLESS_ENABLE_UPDATE_CHECK: "true"

      PAPERLESS_SECRET_KEY: $SECRET

      PAPERLESS_TIME_ZONE: $TZ

      PAPERLESS_OCR_LANGUAGE: 

      PAPERLESS_OCR_DESKEW: "true"
      PAPERLESS_OCR_ROTATE_PAGES: "true"
      PAPERLESS_OCR_ROTATE_PAGES_THRESHOLD: 12
      PAPERLESS_OCR_OUTPUT_TYPE: pdf
      PAPERLESS_OCR_PAGES: 0
      #PAPERLESS_OCR_IMAGE_DPI: none
      #PAPERLESS_OCR_USER_ARGS=<json>

      PAPERLESS_TASK_WORKERS: 2

      PAPERLESS_THREADS_PER_WORKER: 2
      PAPERLESS_WORKER_TIMEOUT: 1800
      PAPERLESS_WORKER_RETRY: 1810
      
      PAPERLESS_CONSUMER_POLLING: 0
      PAPERLESS_CONSUMER_POLLING_RETRY_COUNT: 5
      PAPERLESS_CONSUMER_POLLING_DELAY: 5
      PAPERLESS_CONSUMER_INOTIFY_DELAY: 0.5
      PAPERLESS_CONSUMER_DELETE_DUPLICATES: "false"
      
      PAPERLESS_CONSUMER_RECURSIVE: "false"
      PAPERLESS_CONSUMER_SUBDIRS_AS_TAGS: "false"
      
      PAPERLESS_CONSUMER_ENABLE_BARCODES: "false"
      PAPERLESS_CONSUMER_BARCODE_TIFF_SUPPORT: "false"
      PAPERLESS_CONSUMER_BARCODE_STRING: PATCHT
      
      PAPERLESS_CONVERT_MEMORY_LIMIT: 0
      PAPERLESS_CONVERT_TMPDIR: none
      PAPERLESS_POST_CONSUME_SCRIPT: 
      
      PAPERLESS_FILENAME_DATE_ORDER: none
      PAPERLESS_NUMBER_OF_SUGGESTED_DATES: 3
      PAPERLESS_DATE_ORDER: DMY
      
      PAPERLESS_THUMBNAIL_FONT_NAME: "/usr/share/fonts/liberation/LiberationSerif-Regular.ttf"
      PAPERLESS_CONSUMER_IGNORE_PATTERNS: '[".DS_STORE/*", "._*", ".stfolder/*", ".stversions/*", ".localized/*", "desktop.ini"]'

```


`#PAPERLESS_OCR_IMAGE_DPI: none` was already causing issues is now deactivated - confirmed as this should be a number or not set at all.

### Steps to reproduce

1. 2. Place a PDF in consume folder.

### Webserver logs

```bash
documents.consumer.ConsumerError: Dokument_20231221_163019_000497.pdf: Error occurred while consuming document Dokument_20231221_163019_000497.pdf: BadArgsError: invalid page subrange '1-0'
 [2024-01-06 16:20:42,885] [ERROR] [celery.app.trace] Task documents.tasks.consume_file[62b219ad-ba05-4b5d-bf9f-1e197773239c] raised unexpected: ConsumerError("Dokument_20240106_155055_000631.pdf: Error occurred while consuming document Dokument_20240106_155055_000631.pdf: BadArgsError: invalid page subrange '1-0'")
 Traceback (most recent call last):
   File "/usr/src/paperless/src/paperless_tesseract/parsers.py", line 353, in parse
     ocrmypdf.ocr(**args)
   File "/usr/local/lib/python3.11/site-packages/ocrmypdf/api.py", line 374, in ocr
     check_options(options, plugin_manager)
   File "/usr/local/lib/python3.11/site-packages/ocrmypdf/_validation.py", line 247, in check_options
     _check_plugin_invariant_options(options)
   File "/usr/local/lib/python3.11/site-packages/ocrmypdf/_validation.py", line 236, in _check_plugin_invariant_options
     check_options_ocr_behavior(options)
   File "/usr/local/lib/python3.11/site-packages/ocrmypdf/_validation.py", line 207, in check_options_ocr_behavior
     options.pages = _pages_from_ranges(options.pages)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```


### Browser logs

```bash
[2024-01-06 16:20:42,137] [ERROR] [paperless.consumer] Error occurred while consuming document Dokument_20240106_155055_000631.pdf: BadArgsError: invalid page subrange '1-0'
Traceback (most recent call last):
  File "/usr/src/paperless/src/paperless_tesseract/parsers.py", line 353, in parse
    ocrmypdf.ocr(**args)
  File "/usr/local/lib/python3.11/site-packages/ocrmypdf/api.py", line 374, in ocr
    check_options(options, plugin_manager)
  File "/usr/local/lib/python3.11/site-packages/ocrmypdf/_validation.py", line 247, in check_options
    _check_plugin_invariant_options(options)
  File "/usr/local/lib/python3.11/site-packages/ocrmypdf/_validation.py", line 236, in _check_plugin_invariant_options
    check_options_ocr_behavior(options)
  File "/usr/local/lib/python3.11/site-packages/ocrmypdf/_validation.py", line 207, in check_options_ocr_behavior
    options.pages = _pages_from_ranges(options.pages)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ocrmypdf/_validation.py", line 174, in _pages_from_ranges
    raise BadArgsError(
ocrmypdf.exceptions.BadArgsError: invalid page subrange '1-0'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/asgiref/sync.py", line 349, in main_wrap
    raise exc_info[1]
  File "/usr/src/paperless/src/documents/consumer.py", line 446, in try_consume_file
    document_parser.parse(self.working_copy, mime_type, self.filename)
  File "/usr/src/paperless/src/paperless_tesseract/parsers.py", line 420, in parse
    raise ParseError(f"{e.__class__.__name__}: {e!s}") from e
documents.parsers.ParseError: BadArgsError: invalid page subrange '1-0'

```
<img width="1839" alt="image" src="https://github.com/paperless-ngx/paperless-ngx/assets/5657002/8981334f-df2e-4327-81a0-b6d10a860790">


### Paperless-ngx version

2.3.0

### Host OS

linux

### Installation method

Docker - official image

### Browser

_No response_

### Configuration changes

_No response_

### Other

_No response_

### Please confirm the following

- [X] I believe this issue is a bug that affects all users of Paperless-ngx, not something specific to my installation.
- [X] I have already searched for relevant existing issues and discussions before opening this report.
- [X] I have updated the title field above with a concise description.


Discussion:
This needs a documentation update.  PAPERLESS_OCR_PAGES should be noted as defaulting to not set, working against all pages.  And should probably be noted as being 1 or more when set, since 1-0 doesn't make sense.
Yea it used to default to 0, would making that map to None also work?
@stumpylog But it's also broken on UI:

<img width="649" alt="image" src="https://github.com/paperless-ngx/paperless-ngx/assets/5657002/6914ed91-62a2-4e3e-812c-1c43e1aaab21">

Documentation tells 0 is allowed for unlimeted pages:
https://docs.paperless-ngx.com/configuration/#PAPERLESS_OCR_PAGES

<img width="1203" alt="image" src="https://github.com/paperless-ngx/paperless-ngx/assets/5657002/9c47c19e-3cd9-4d47-ba71-fde5c441338d">

But UI also doesn't accept it.

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
@@ -238,7 +238,7 @@ def construct_ocrmypdf_parameters(
             ocrmypdf_args["rotate_pages"] = True
             ocrmypdf_args["rotate_pages_threshold"] = self.settings.rotate_threshold
 
-        if self.settings.pages is not None:
+        if self.settings.pages is not None and self.settings.pages > 0:
             ocrmypdf_args["pages"] = f"1-{self.settings.pages}"
         else:
             # sidecar is incompatible with pages


Test patch: