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/

insert_upsert_implementation always tries to call transform() after the
insert when --detect-types is set, but for an empty CSV (header row
only, no data rows) insert_all is a no-op and the table is never
created. transform() then asserts table.exists() and crashes.

Guard the transform call with table.exists(). Added a regression test
that fails on main and passes here. Same guard applied to the analogous
multi-file path further down.

Closes simonw#702

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
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