Skip to content

Guard transform when --detect-types CSV has only a header row (closes #702)#733

Open
guzenkopavel wants to merge 1 commit intosimonw:mainfrom
guzenkopavel:fix-702-detect-types-header-only-csv
Open

Guard transform when --detect-types CSV has only a header row (closes #702)#733
guzenkopavel wants to merge 1 commit intosimonw:mainfrom
guzenkopavel:fix-702-detect-types-header-only-csv

Conversation

@guzenkopavel
Copy link
Copy Markdown

@guzenkopavel guzenkopavel commented May 4, 2026

Fixes #702.

When sqlite-utils insert --csv --detect-types is given a CSV file that contains only the header row (no data rows), the table is never created — but the post-insert call to db.table(table).transform(types=tracker.types) still runs and trips an assertion:

AssertionError: Cannot transform a table that doesn't exist yet

This adds the db.table(table).exists() guard suggested by the issue author (@nis-djom), plus a regression test (tests/test_cli.py::test_insert_detect_types_header_only_csv) that exercises the exact scenario from the issue body.

Local pytest -q on the patched branch: 1041 passed, 16 skipped, 6.40s.


📚 Documentation preview 📚: https://sqlite-utils--733.org.readthedocs.build/en/733/

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.

Insert CSV with --detect-types crashes for CSV files that contain only a header row

1 participant