Repository: paperless-ngx/paperless-ngx

Issue:
[BUG] At Splitting: Custom field leads to "The following error occurred while storing document 15_2-2.pdf after parsing: CustomField matching query does not exist."
### Description

Document with custom field leads to error message on splittting. No workflow active.

"The following error occurred while storing document 15_2-2.pdf after parsing: CustomField matching query does not exist."



### Steps to reproduce

1. Go to Ducuments
2. Edit document
3. Splitting into separate Pages
4. Error message appears

### Webserver logs

```bash
[2024-04-06 11:24:55,324] [DEBUG] [paperless.tasks] Skipping plugin CollatePlugin
[2024-04-06 11:24:55,325] [DEBUG] [paperless.tasks] Executing plugin BarcodePlugin
[2024-04-06 11:24:55,325] [DEBUG] [paperless.barcodes] Scanning for barcodes using PYZBAR
[2024-04-06 11:24:55,542] [INFO] [paperless.tasks] BarcodePlugin completed with no message
[2024-04-06 11:24:55,545] [DEBUG] [paperless.tasks] Executing plugin WorkflowTriggerPlugin
[2024-04-06 11:24:55,547] [INFO] [paperless.tasks] WorkflowTriggerPlugin completed with:
[2024-04-06 11:24:55,554] [INFO] [paperless.consumer] Consuming 15_2-2.pdf
[2024-04-06 11:24:55,556] [DEBUG] [paperless.consumer] Detected mime type: application/pdf
[2024-04-06 11:24:55,562] [DEBUG] [paperless.consumer] Parser: RasterisedDocumentParser
[2024-04-06 11:24:55,565] [DEBUG] [paperless.consumer] Parsing 15_2-2.pdf...
[2024-04-06 11:24:55,572] [INFO] [paperless.parsing.tesseract] pdftotext exited 0
[2024-04-06 11:24:55,711] [DEBUG] [paperless.parsing.tesseract] Calling OCRmyPDF with args: {'input_file': PosixPath('/tmp/paperless/paperless-ngx2bzkbofi/15_2-2.pdf'), 'output_file': PosixPath('/tmp/paperless/paperless-6d3y7xqr/archive.pdf'), 'use_threads': True, 'jobs': 4, 'language': 'deu+eng', 'output_type': 'pdfa', 'progress_bar': False, 'color_conversion_strategy': 'RGB', 'skip_text': True, 'clean': True, 'deskew': True, 'rotate_pages': True, 'rotate_pages_threshold': 6.0, 'sidecar': PosixPath('/tmp/paperless/paperless-6d3y7xqr/sidecar.txt')}
[2024-04-06 11:24:55,809] [INFO] [ocrmypdf._pipeline] skipping all processing on this page
[2024-04-06 11:24:55,812] [INFO] [ocrmypdf._pipelines.ocr] Postprocessing...
[2024-04-06 11:24:55,916] [INFO] [ocrmypdf._pipeline] Image optimization ratio: 1.00 savings: 0.0%
[2024-04-06 11:24:55,917] [INFO] [ocrmypdf._pipeline] Total file size ratio: 0.72 savings: -39.6%
[2024-04-06 11:24:55,918] [INFO] [ocrmypdf._pipelines._common] Output file is a PDF/A-2B (as expected)
[2024-04-06 11:24:55,922] [DEBUG] [paperless.parsing.tesseract] Incomplete sidecar file: discarding.
[2024-04-06 11:24:55,946] [INFO] [paperless.parsing.tesseract] pdftotext exited 0
[2024-04-06 11:24:55,946] [DEBUG] [paperless.consumer] Generating thumbnail for 15_2-2.pdf...
[2024-04-06 11:24:55,950] [DEBUG] [paperless.parsing] Execute: convert -density 300 -scale 500x5000> -alpha remove -strip -auto-orient -define pdf:use-cropbox=true /tmp/paperless/paperless-6d3y7xqr/archive.pdf[0] /tmp/paperless/paperless-6d3y7xqr/convert.webp
[2024-04-06 11:24:56,727] [INFO] [paperless.parsing] convert exited 0
[2024-04-06 11:24:56,797] [DEBUG] [paperless.consumer] Saving record to database
[2024-04-06 11:24:56,798] [DEBUG] [paperless.consumer] Creation date from st_mtime: 2024-04-06 11:24:52.835078+02:00
[2024-04-06 11:24:56,831] [ERROR] [paperless.consumer] The following error occurred while storing document 15_2-2.pdf after parsing: CustomField matching query does not exist.
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/asgiref/sync.py", line 327, in main_wrap
    raise exc_info[1]
  File "/usr/src/paperless/src/documents/consumer.py", line 675, in try_consume_file
    document = self._store(text=text, date=date, mime_type=mime_type)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/paperless/src/documents/consumer.py", line 851, in _store
    self.apply_overrides(document)
  File "/usr/src/paperless/src/documents/consumer.py", line 905, in apply_overrides
    field = CustomField.objects.get(pk=field_id)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/models/query.py", line 637, in get
    raise self.model.DoesNotExist(
documents.models.CustomField.DoesNotExist: CustomField matching query does not exist.
[2024-04-06 11:24:56,833] [DEBUG] [paperless.parsing.tesseract] Deleting directory /tmp/paperless/paperless-6d3y7xqr
```


### Browser logs

_No response_

### Paperless-ngx version

2.7.0

### Host OS

Docker on Synology NAS - DSM 7.2

### Installation method

Docker - official image

### Browser

Firefox

### 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:
I can confirm this. there is also a ASN Bug.
![image](https://github.com/paperless-ngx/paperless-ngx/assets/115543711/7591a7ac-7f7c-444c-80b2-cdabe1ee49ed)
![image](https://github.com/paperless-ngx/paperless-ngx/assets/115543711/f28a2424-099d-4953-b16d-35855c6b9a88)


Resolving patch:
diff --git a/src/documents/data_models.py b/src/documents/data_models.py
--- a/src/documents/data_models.py
+++ b/src/documents/data_models.py
@@ -116,7 +116,7 @@ def from_document(doc) -> "DocumentMetadataOverrides":
             ).values_list("id", flat=True),
         )
         overrides.custom_field_ids = list(
-            doc.custom_fields.values_list("id", flat=True),
+            doc.custom_fields.values_list("field", flat=True),
         )
 
         groups_with_perms = get_groups_with_perms(


Test patch: