-
-
Notifications
You must be signed in to change notification settings - Fork 209
Description
🔍 Bug Summary
API returns 400 Bad Request when custom field string values are over 128 characters and required fields (correspondent, storage_path) are missing from the update payload.
📖 Description
When Paperless-AI updates a document via the Paperless-ngx API, the PATCH request fails with two key validation errors:
Problem 1: Custom Field String Length Exceeded
- The AI-generated summaries for STRING type custom fields in Paperless-ngx can exceed the 128 character limit enforced by Paperless-ngx validation.
- Example: One custom field is 318 characters, another is 378 characters, both far above the 128 character max.
Problem 2: Missing Required Fields (correspondent, storage_path)
- Paperless-ngx API requires fields like correspondent and storage_path in PATCH if they are marked as required, even if their value does not change.
- The current update logic removes correspondent from the PATCH body if it already exists and does not add storage_path at all, causing the API to reject the update.
The result is that PATCH requests fail with HTTP 400 and validation errors for both custom fields and missing required document fields.
🔄 Steps to Reproduce
- Configure Paperless-AI v3.0.7 with Paperless-ngx v2.19.3 and enable required fields (correspondent, storage_path) in Paperless-ngx document metadata.
- Set up STRING type custom fields in Paperless-ngx.
- Process a document with Paperless-AI that returns custom field summaries longer than 128 chars.
- Observe that document updates fail with 400 Bad Request referencing both the long custom fields and missing metadata fields.
✅ Expected Behavior
- Custom field values should be truncated to 128 characters before sending to Paperless-ngx.
- Required metadata fields like correspondent and storage_path should always be included in PATCH, taken either from the update or preserved from the original document.
- The update should succeed regardless of whether the field value has changed.
- A warning should be logged when values are truncated or when defaults are used.
❌ Actual Behavior
- API returns 400 Bad Request with validation error: 'Ensure this value has at most 128 characters.'
- Custom field 1: 318 characters (limit is 128)
- Custom field 2: 378 characters (limit is 128)
- correspondent: 'This field is required.' (field missing in PATCH body)
- storage_path: 'This field is required.' (field missing in PATCH body)
- Document update fails completely.
- Error: Request failed with status code 400
(For privacy: document title and field values omitted.)
🏷️ Paperless-AI Version
v3.0.7
📜 Docker Logs
[DEBUG] Final update data: { title: '...', created: '...', document_type: 41, custom_fields: [ ... ], language: 'de' }
AxiosError: Request failed with status code 400
API Error Response:
{
"correspondent": ["This field is required."],
"storage_path": ["This field is required."],
"custom_fields": [
{ "non_field_errors": ["Ensure this value has at most 128 characters (it has 318)."] },
{ "non_field_errors": ["Ensure this value has at most 128 characters (it has 378)."] }
]
}📜 Paperless-ngx Logs
[WARNING] Bad Request: /api/documents/242/🖼️ Screenshots of your settings page
No response
🖥️ Desktop Environment
Linux
💻 OS Version
No response
🌐 Browser
Firefox
🔢 Browser Version
No response
🌐 Mobile Browser
No response
📝 Additional Information
- I have checked existing issues and this is not a duplicate
- I have tried debugging this issue on my own
- I can provide a fix and submit a PR
- I am sure that this problem is affecting everyone, not only me
- I have provided all required information above
📌 Extra Notes
Root Cause Analysis:
Custom Field Length:
Paperless-AI does not validate or truncate custom field values before sending them to Paperless-ngx. Paperless-ngx enforces a 128 character max on STRING type custom fields.
Missing Required Fields:
Paperless-AI removes correspondent from the update if it already exists, and does not include storage_path at all in the PATCH payload. If Paperless-ngx requires these fields, their absence produces a validation error, even if value didn't change. This happens in services/paperlessService.js near the PATCH logic. The following code deletes them:
if (currentDoc.correspondent && updates.correspondent) {
delete updates.correspondent;
}Fix: Always preserve existing values of required fields in the PATCH payload when not updating.
Proposed Fixes:
- Truncate custom field string values to 128 chars.
- Always include correspondent and storage_path, either from updates or by copying from the original document.
- Adjust AI prompt to always produce <= 128 chars custom field summaries.
Paperless-ngx Context:
- Version: v2.19.3
- PATCH API expects all required metadata fields (correspondent, storage_path, etc.) to be included when required.
- Omitting required fields (even if a value is already present remotely) will make the API return 400 error in strict Paperless-ngx configurations.