Repository navigation
Long text custom fields, shared write-back and custom field type check - #364
Merged
Merged
Conversation
Background Paperless-ngx has a `longtext` custom field type without the 128-character limit of `string`. The processing path already handled it: the validator applies the length guard to `string` only, the prompt builders treat any other type as free text, and the settings route stores whatever type it is given. Only the type selector in Settings lacked the option, so using a long text field meant editing the CUSTOM_FIELDS JSON by hand. PR #220 and PR #255 both add the option. Changes - Settings: add "Long text" (`longtext`) to the custom field type selector and label `string` as "Text (up to 128 characters)", so the difference is visible where the type is chosen. - New offline test `custom-field-longtext`: a longtext value over 128 characters passes validation unchanged (line breaks included), a string value over 128 is still skipped, and the selector offers both types. Registered in the runner under the processing area. Not taken from #255: the buildUpdateData refactor into dataProcessingUtils.js (the pipeline is being unified separately), the Ollama change (hard-coded num_ctx 32k and num_predict -1 override the configured context and RESPONSE_TOKENS budget), and the IDE files. Testing - node scripts/run-tests.js --test custom-field-longtext: passes; fails against the old view. - node scripts/run-tests.js --all in a clean worktree: 108 passed, 7 skipped (need a running server or pdftoppm), 0 failed. - eslint and prettier clean on the changed JS files. Impact UI only: one more option in the custom field type selector. No change to processing, the API or stored configuration. Upstream Status Not applicable (fork-only UI). Co-Authored-By: rsaether76 <264263539+rsaether76@users.noreply.github.com> Co-Authored-By: OvisMaximus <5701377+OvisMaximus@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Background server.js (scheduled scan), routes/setup.js (manual queue) and services/mistralOcrService.js (OCR) each carried their own copy of buildUpdateData/saveDocumentChanges, and the copies had drifted apart: - The queue sent the Paperless-ngx update in parallel with the local bookkeeping and never checked the result, so a rejected update still marked the document as processed and wrote history and metrics. It also crashed on metrics-less analyses and did not pass the document id to the creation guard. - The OCR path dropped custom fields entirely, never saved the snapshot "restore original" needs, did not apply the AI-processed tag when tagging was off, and let a failing document type or correspondent lookup abort the whole run. - The scan crashed on a null custom field entry. PR #255 moved the shared parts into a helper module; this does the same with the whole write-back. Changes - New services/documentProcessingService.js (singleton) with buildUpdateData() and saveDocumentChanges(), built from the scan copy plus the queue copy's null-entry guard and dashboard invalidation. - server.js, routes/setup.js and mistralOcrService._runAiAnalysis() call it; their copies and the now unused validateCustomFieldValue imports are gone. - History and the processed list record the document's title when title generation is off (the OCR path did this already; the others stored null). - Tests: new document-processing-service (payload, snapshot order, rejected update, title fallback, OCR custom fields, all three call sites); mistral-ocr-no-processed-on-update-failure mocks the real processTags() contract and asserts the snapshot; ai-processed-tag-without-tags reads the new module. Testing - node scripts/run-tests.js --all in a clean worktree: 109 passed, 7 skipped (need a running server or pdftoppm), 0 failed. - The new test fails against the previous call sites (OCR custom fields, local copies). - Real module graph loads (service, OCR service, routes) without cycles. - eslint and prettier clean on all changed files; OpenAPI unchanged. Impact Queue and OCR processing behave like the scheduled scan. OCR-processed documents now get custom fields and can be restored. No API or config change. Upstream Status Not applicable (fork-only code path). Co-Authored-By: OvisMaximus <5701377+OvisMaximus@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…#255) Background The history stored the model's raw answer for correspondent and document type, not what was written to Paperless-ngx. The two differ whenever the answer is mapped to an existing entry (another spelling via the creation guard, a restricted list) or not applied at all (restriction without a match, detection switched off). The History page then showed names that exist nowhere in Paperless-ngx, its correspondent filter listed them, the document type statistics counted them, and a correspondent merge, which rewrites history rows by name, could not find them. PR #255 fixed this by fetching both names from Paperless-ngx after the update. Changes - buildUpdateData() keeps the name of the entity getOrCreateCorrespondent() and getOrCreateDocumentType() returned, as history-only keys next to _customFieldsForHistory; no extra API request. - saveDocumentChanges() writes those names to the history and strips them from the payload. Nothing set means an empty column. - Test document-processing-service covers a mapped name and the two "not set" cases (restriction without a match, detection off). Testing - node scripts/run-tests.js --all in a clean worktree: 109 passed, 7 skipped (need a running server or pdftoppm), 0 failed. - The two new cases fail against the previous commit. Impact New history rows show the names Paperless-ngx has; rows for fields that were not set stay empty instead of showing the model's suggestion. Existing rows are not rewritten. Upstream Status Not applicable (fork-only code path). Co-Authored-By: OvisMaximus <5701377+OvisMaximus@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ype (#255) Background When a custom field's name already exists in Paperless-ngx, the create request fails with 400 and createCustomFieldSafely() takes the existing field instead. Its data type was never compared, so a field added as "Long text" while Paperless-ngx has it as `string` saved without a word, and every value over 128 characters was dropped during processing. PR #255 added the comparison and turned it into a 400. Changes - paperlessService.findCustomFieldTypeConflicts(): refreshes the custom field cache once and lists configured fields whose name exists with another data_type (case-insensitive); null when Paperless-ngx cannot be asked. - POST /settings runs the check before anything is saved or created and answers 400 { success: false, error } naming the field and both types. Only fields added or changed in this save are refused; entries configured before only warn, so a mismatch in an operator-injected CUSTOM_FIELDS cannot lock the settings page. An unreachable Paperless-ngx skips the check with a warning instead of blocking the save. - Unlike #255, the save order and the handling of other field creation errors stay as they were. - OpenAPI: the 400 response of POST /settings describes the new case and the actual { success, error } body; openapi.json regenerated. - New offline test settings-custom-field-type-conflict (mount-router): refusal without save/create, legacy entry warns only, matching and new fields are saved and created, unreachable Paperless-ngx does not block. Testing - node scripts/run-tests.js --all in a clean worktree: 110 passed, 7 skipped (need a running server or pdftoppm), 0 failed. - The refusal case fails against the previous commit. - eslint and prettier clean on all changed files. Impact Saving Settings can now fail with a clear message when a newly added custom field conflicts with Paperless-ngx. The settings page already shows the error text in its dialog. Upstream Status Not applicable (fork-only settings). Co-Authored-By: OvisMaximus <5701377+OvisMaximus@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Background With PROCESS_PREDEFINED_DOCUMENTS=yes, a TAGS value that matches no tag in Paperless-ngx makes the scan find nothing, and the log only said "None of the specified tags were found" without saying which ones were looked for. Changes - Both warnings in paperlessService (document listing and the TAGS lookup) list the configured tag names. Testing - node scripts/run-tests.js --all in a clean worktree: 110 passed, 7 skipped (need a running server or pdftoppm), 0 failed. Impact Log text only. Upstream Status Not applicable. Co-Authored-By: OvisMaximus <5701377+OvisMaximus@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This was referenced Sep 27, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brings in what #220 and #255 set out to do, rebuilt on the current
main. Both PRs predate the UI migration and no longer apply cleanly; #255 also conflicts withmain.Changes
Long text custom fields (#220, #255)
The type selector in Settings offers "Long text" (
longtext), andstringis labelled "Text (up to 128 characters)". Processing already handledlongtext: the 128-character guard only applies tostring.One write-back for scan, queue and OCR (#255)
server.js,routes/setup.jsandmistralOcrService.jseach had their own copy ofbuildUpdateData/saveDocumentChanges, and the copies had drifted. They now shareservices/documentProcessingService.js. This fixes:History records what was actually set (#255)
The history stored the model's raw answer for correspondent and document type, so it could show a name that exists nowhere in Paperless-ngx (for example "Deutsche Telekom AG" when the existing "Telekom" was used). It now stores the name of the entity that was written. The name comes from the lookup that already happens, so there is no extra API request. The field stays empty when nothing was set.
Custom field type conflicts are refused on save (#255)
POST /settingsanswers 400 when a newly added or changed field's name already exists in Paperless-ngx with another type. Before, the existing field was adopted silently. Entries that were already configured only log a warning, so an operator-injectedCUSTOM_FIELDScannot lock the page. An unreachable Paperless-ngx skips the check instead of blocking the save. OpenAPI updated.Log (#255)
"None of the specified tags were found" now names the tags.
Not taken from #255
num_ctxof 32k andnum_predict: -1would override the configured context andRESPONSE_TOKENS..idea/files.Testing
node scripts/run-tests.js --allin a clean worktree: 110 passed, 7 skipped (they need a running server orpdftoppm), 0 failed.custom-field-longtext,document-processing-service,settings-custom-field-type-conflict. Each fails against the code it covers.Thanks to @rsaether76 and @OvisMaximus. Both are credited as co-authors on the commits.
Supersedes #220, #255.
🤖 Generated with Claude Code