Skip to content

fix(transformers): strip the UTF-8 BOM before parsing CSV - #1179

Open
xdAsaah wants to merge 1 commit into
dynamiq-ai:mainfrom
xdAsaah:fix/csv-to-list-bom
Open

xdAsaah wants to merge 1 commit into
dynamiq-ai:mainfrom
xdAsaah:fix/csv-to-list-bom

Conversation

@xdAsaah

@xdAsaah xdAsaah commented Nov 28, 2026

Copy link
Copy Markdown

Problem

CSVToList decodes a BytesIO with plain utf-8 and passes the text to csv.DictReader. Excel's "CSV UTF-8" export — the usual export when the data holds non-ASCII text — starts with a UTF-8 BOM, which survives the decode as U+FEFF, so the first column is polluted:

  • with a header (is_header_exists=True, the default) the first row's key comes out as "\ufeffname" instead of "name". Reading it by the header the user sees fails, and in an agent flow the dirty key is handed to the model as a field name;
  • without a header the first cell's value carries the marker ("\ufeffname").

The project already reads CSV through utf-8-sig: CSVConverter opens paths and BytesIO with encoding="utf-8-sig" (dynamiq/nodes/converters/csv.py:148, :177) and the Excel converter reads CSV the same way (dynamiq/components/converters/excel.py:249, :296). The transformer is the one place that does not, so the two CSV entry points disagree on the same file.

Compatibility

Data without a BOM decodes exactly as before — utf-8-sig is plain utf-8 when no BOM is present — and the string input path only loses a leading U+FEFF. No signature, output shape or error behavior changes otherwise.

No charset guessing is added on purpose: charset_normalizer reads a short GBK sample as euc-kr and returns Korean mojibake, which would be worse than the decode error it reports today.

Verified

Before the change (its parent) and after, with the repo's test dependencies installed:

  • tests/unit/nodes/transformers/test_csv_to_list_bom.py (new, 4 cases): 3 failed → 4 passed
    • BytesIO + BOM + header: {"\ufeffname": "Alice", "age": "30"} → {"name": "Alice", "age": "30"}
    • str + BOM + header: same
    • BytesIO + BOM, is_header_exists=False: {"column0": "\ufeffname"} → {"column0": "name"}
    • BytesIO without BOM: unchanged
  • Existing tests/integration/nodes/transformers/test_csv_excel_transformers.py: 6 passed, unchanged
  • Mutation checks: decoding the BytesIO with plain utf-8 reddens both BOM byte cases; dropping the removeprefix reddens the string case — each half is guarded on its own
  • flake8 --max-line-length=120 and isort --profile black clean on both files

This change was prepared with AI assistance.

@xdAsaah
xdAsaah requested a review from a team as a code owner November 28, 2026 09:43
Excel's "CSV UTF-8" export starts with a BOM, and CSVToList decoded a BytesIO with plain
utf-8 and handed the resulting U+FEFF to the parser. With a header row the first column's
key came out as "\ufeffname", so a lookup by the header the user sees ("name") missed it,
and in an agent flow the dirty key reached the model as a field name; without a header
the first cell kept the marker in its value.

A BytesIO now decodes as utf-8-sig, which drops the BOM and leaves data without one
untouched, and a string that already carries the decoded marker has it removed before
parsing. CSVConverter and the Excel converter already read CSV through utf-8-sig (nodes/
converters/csv.py, components/converters/excel.py), so the transformer now agrees with
them on the same file.

No charset guessing is added: charset_normalizer reads a short GBK sample as euc-kr and
returns Korean mojibake, which is worse than the decode error this reports today.
@xdAsaah
xdAsaah force-pushed the fix/csv-to-list-bom branch from 58d9d76 to 0d7bb8f Compare November 28, 2026 09:48

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant