docling icon indicating copy to clipboard operation
docling copied to clipboard

Repeated CSV backend conversion loses non-comma column boundaries

Open WitBlue6 opened this issue 1 month ago • 0 comments

Bug

Calling CsvDocumentBackend.convert() twice on the same loaded backend changes the table for non-comma delimiters. The first conversion consumes self.content; the next dialect sniff starts at EOF, falls back to csv.excel, then rewinds only for parsing. Semicolon/tab/pipe input is consequently collapsed into one column.

Reproduction (current main, docling-slim 2.137.0)

from io import BytesIO
from docling.backend.csv_backend import CsvDocumentBackend
from docling.datamodel.base_models import InputFormat
from docling.datamodel.document import InputDocument

stream = BytesIO(b"name;value\nAlice;1\n")
in_doc = InputDocument(path_or_stream=stream, filename="repeat.csv",
                       format=InputFormat.CSV, backend=CsvDocumentBackend)
backend = CsvDocumentBackend(in_doc=in_doc, path_or_stream=stream)
print(backend.convert().tables[0].data.num_cols)  # 2
print(backend.convert().tables[0].data.num_cols)  # 1

Expected: both conversions retain the same two columns and cell values before unloading. Proposed fix: rewind the decoded content before dialect sniffing, with regression coverage for comma, semicolon, tab, and pipe. Found by code inspection and reproduced locally; no production incident is claimed. This report and patch were prepared with AI assistance.

WitBlue6 avatar Oct 10 '26 19:10 WitBlue6