fix: resolve select field label-to-ID mapping for custom fields#943
fix: resolve select field label-to-ID mapping for custom fields#943SEWADE wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds Paperless-ngx select-option modeling and XML escaping helpers, and updates prompt XML generation to emit escaped attribute/text and nested Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@app_llm.go`:
- Around line 404-412: The XML being built in the block that writes field and
option nodes must escape attribute values and text to avoid breaking XML when
names/labels contain special characters; add helper replacers/escape functions
(e.g., xmlAttrEscaper/xmlTextEscaper with escapeXMLAttr and escapeXMLText) and
use them when writing attributes and text in xmlBuilder.WriteString (escape
field.Name and field.DataType for attributes, option IDs with escapeXMLAttr, and
option labels with escapeXMLText) so all interpolated values are properly
encoded before writing the <field> and <option> nodes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
Problem
When using custom fields of type
select, paperless-gpt fails to update documents with a 400 error from the Paperless-ngx API:error updating document: 400, {"custom_fields":[{"non_field_errors":["Value must be an id of an element in [...]"]}]}Root cause: Two issues combined:
The
CustomFieldstruct did not includeExtraData, so theselect_optionsfrom the API response were silently discarded during JSON parsing.The LLM prompt for custom field suggestions only contained
type="select"without the available options. The LLM therefore returned human-readable labels (e.g."Sonstiges") instead of the required option IDs (e.g."Ien0jKSg1o3E4E0t"), causing the API to reject the update.Fix
SelectOptionandCustomFieldExtraDatastructs and anExtraDatafield toCustomFieldso select options are properly deserialized.<option id="...">label</option>entries forselect-type fields, so the LLM can return the correct option ID directly.Tested
Verified on a Paperless-ngx instance with two
select-type custom fields (8 and 12 options respectively). Documents are now processed and saved successfully.Summary by CodeRabbit