Skip to content

Don't transform empty CSV table that was never created#736

Open
c-tonneslan wants to merge 1 commit into
simonw:mainfrom
c-tonneslan:fix/detect-types-empty-csv
Open

Don't transform empty CSV table that was never created#736
c-tonneslan wants to merge 1 commit into
simonw:mainfrom
c-tonneslan:fix/detect-types-empty-csv

Conversation

@c-tonneslan
Copy link
Copy Markdown

@c-tonneslan c-tonneslan commented May 17, 2026

Closes #702.

When a CSV file is header-only, `insert_all` is a no-op so the table never gets created, but the `--detect-types` path still calls `transform(types=tracker.types)` afterwards and `transform` asserts `table.exists()`. Result is the `AssertionError: Cannot transform a table that doesn't exist yet` traceback from the issue.

Gate the `transform` call on `table.exists()` so the empty case is a clean no-op. Applied the same guard to the analogous loop further down in `memory`-style multi-file insertion. Added a regression test that fails on main and passes here.


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

Closes simonw#702.

A CSV that's only a header row leaves insert_all with no rows, so no
table gets created. The follow-up transform(types=tracker.types) hit
the 'Cannot transform a table that doesn't exist yet' assertion. Guard
both insert paths on the table actually existing.

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
@c-tonneslan c-tonneslan force-pushed the fix/detect-types-empty-csv branch from da1d013 to 0c5e9eb Compare May 18, 2026 14:09
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