Skip to content

fix: write a header-only CSV when no enrichment run returns a row - #196

Open
AkashBR wants to merge 1 commit into
parallel-web:mainfrom
AkashBR:fix/csv-empty-results
Open

AkashBR wants to merge 1 commit into
parallel-web:mainfrom
AkashBR:fix/csv-empty-results

Conversation

@AkashBR

@AkashBR AkashBR commented Dec 3, 2026

Copy link
Copy Markdown

Fixes #195

enrich run with a CSV target crashed with IndexError: list index out of range when no run in the task group returned a row (every run failed, or every output failed validation). process_csv took the header from output_rows[0], but run_tasks returns [] in that case. The crash came after the runs were billed, and the target, already opened for writing, was left empty.

Fix: when there are no rows, build the header from the input and output models plus batch_id and insertion_timestamp, in the same order run_tasks builds its rows, so the target is a valid header-only CSV (as the JSON processor writes []). Runs that return rows are unchanged.

Files: parallel_web_tools/processors/csv.py (+5/−1), tests/test_enrichment.py (new TestProcessCsv, stubbing the SDK client as TestRunTasks does, with one failed run).

How tested: the new test fails on main with the IndexError and passes with the fix. uv run ruff check ., uv run ruff format --check ., uv run tach check and uv run ty check are clean; uv run pytest -q gives 1033 passed (1032 on main). Merges cleanly with the open PRs, including #189, which also edits processors/csv.py.

Not in this PR: the DuckDB processor fails the same way on an empty result (pl.DataFrame([]) has no columns). Happy to follow up.

process_csv took the CSV header from output_rows[0]. When every run in the
task group failed, run_tasks returned an empty list, so enrichment crashed with
IndexError ("Error during enrichment: list index out of range") after the runs
were billed, and the target file had already been truncated to zero bytes.

Build the header from the input and output models when there are no rows, so
the target is a valid header-only CSV, matching the JSON processor, which
writes [] in the same case.
@AkashBR
AkashBR requested a review from a team December 3, 2026 20:09

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.

enrich run crashes with IndexError and empties the CSV target when every run fails

1 participant