Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions haystack/components/converters/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def __init__(
self.quotechar = quotechar

# Basic validation
if conversion_mode not in ("file", "row"):
raise ValueError(f"CSVToDocument: unsupported conversion_mode {conversion_mode!r}. Choose 'file' or 'row'.")
if len(self.delimiter) != 1:
raise ValueError("CSVToDocument: delimiter must be a single character.")
if len(self.quotechar) != 1:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
fixes:
- |
``CSVToDocument`` now rejects an unsupported ``conversion_mode`` in its constructor.
Previously the value was only compared against ``"file"`` in ``run()``, so any other
string, including a typo such as ``"Rows"`` or a value with a trailing space, silently
selected the row mode and produced one ``Document`` per row instead of one per file.
When ``content_column`` was not passed, the raised error also reported
``conversion_mode='row'`` for a component the caller had never configured that way.
14 changes: 14 additions & 0 deletions test/components/converters/test_csv_to_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,20 @@ def test_init_validates_delimiter_and_quotechar(self):
with pytest.raises(ValueError):
CSVToDocument(quotechar='""')

def test_init_rejects_an_unknown_conversion_mode(self):
with pytest.raises(ValueError, match="unsupported conversion_mode 'Rows'"):
CSVToDocument(conversion_mode="Rows") # type: ignore[arg-type]

def test_init_rejects_a_conversion_mode_that_only_differs_in_whitespace_or_case(self):
with pytest.raises(ValueError, match="unsupported conversion_mode 'file '"):
CSVToDocument(conversion_mode="file ") # type: ignore[arg-type]
with pytest.raises(ValueError, match="unsupported conversion_mode ''"):
CSVToDocument(conversion_mode="") # type: ignore[arg-type]

def test_init_accepts_both_documented_conversion_modes(self):
assert CSVToDocument(conversion_mode="file").conversion_mode == "file"
assert CSVToDocument(conversion_mode="row").conversion_mode == "row"

def test_row_mode_large_file_warns(self, caplog, monkeypatch):
# Make the threshold tiny so the warning always triggers.
import haystack.components.converters.csv as csv_mod
Expand Down
Loading