fix: reject an unsupported conversion_mode in CSVToDocument - #13084
Draft
Lesereingrape wants to merge 3 commits into
Draft
Lesereingrape wants to merge 3 commits into
Lesereingrape wants to merge 3 commits into
Conversation
…to row mode CSVToDocument compared conversion_mode only against "file" in run(), so any other value selected the row branch: a typo such as "Rows" silently produced one Document per row instead of one per file, and a value differing only by trailing whitespace raised an error claiming conversion_mode='row'. Validate the Literal in __init__, the way the sibling XLSXToDocument already validates table_format and link_format.
Contributor
|
@Lesereingrape is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
This branch has not been deployed
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.
What happened
CSVToDocumentdeclaresconversion_mode: Literal["file", "row"]but never validates it —__init__only checksdelimiterandquotecharunder a# Basic validationcomment.run()then dispatches withif self.conversion_mode == "file": …and everything else falls through into the row branch. So a mistyped mode is not an error; it quietly changes what the component produces.Measured on
8a5406eewith a 2-row CSV (text,author+ 2 data rows),D:/hs_lane/envpython:Two caller-visible problems in that output:
conversion_mode="Rows"returns a different document count and different content shape than asked for, with no signal at all. DownstreamDocumentconsumers just see more, shorter documents.when conversion_mode='row', which sends the user to look at theircontent_columnargument instead of at their typo.What changed
Validate the
Literalin__init__, the way the sibling converter in the same package already validates its ownLiteralfields —XLSXToDocumentraises for an unknowntable_format(haystack/components/converters/xlsx.py:82-83) and for an unknownlink_format(:84-86). The check joins the existing# Basic validationblock, so the component now fails at construction, where the bad argument is visible, rather than atrun().Nothing about the two valid modes changed:
"file"still yields one Document per file and"row"still requirescontent_columninrun().How it was checked
Added to
test/components/converters/test_csv_to_document.py, next to the existingtest_init_validates_delimiter_and_quotechar:test_init_rejects_an_unknown_conversion_mode—"Rows"raises, matched on the message.test_init_rejects_a_conversion_mode_that_only_differs_in_whitespace_or_case—"file "and""raise.test_init_accepts_both_documented_conversion_modes— control: the two valid values still construct.CSVToDocumentis also instantiated byMultiFileConverter, so that file was run before and after:2 failed, 16 errorson a pristine8a5406eeworktree and the identical2 failed, 16 errorswith the change — those are optional converter dependencies (pypdf,python-docx) missing in my local environment, not this patch.ruff checkandruff format --checkare clean on both changed files. A release note is included (releasenotes/notes/csv-conversion-mode-validation-8f4c2b1d7e9a3056.yaml).Reported in #13070, which shows the same silent mode switch from the caller side.
Disclosure: this PR was prepared, tested and submitted by an AI agent working on behalf of the account owner.
Related Issues
Proposed Changes:
conversion_modecheck to the existing# Basic validationblock inCSVToDocument.__init__, so an unsupported value fails at construction instead of silently falling into the row branch inrun().ValueError.How did you test it?
python -m pytest test/components/converters/test_csv_to_document.py -q— 2 failed, 18 passed without the fix, 20 passed with it (details in "How it was checked" above).Notes for the reviewer
The error message quotes the offending value with
!r, which is what makes"Rows"and"file "distinguishable in the message; the existing tests match on it.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.