insert: don't crash on header-only CSV with --detect-types#739
Closed
c-tonneslan wants to merge 1 commit into
Closed
insert: don't crash on header-only CSV with --detect-types#739c-tonneslan wants to merge 1 commit into
c-tonneslan wants to merge 1 commit into
Conversation
When the input has a header but no data rows, the insert path never
creates the table - the row loop has nothing to feed into the first
insert. The post-insert tracker.transform call then asserts the table
exists and blows up:
AssertionError: Cannot transform a table that doesn't exist yet
Reported in simonw#702 with the exact fix in the body. Guard the transform
on db[table].exists() so an empty CSV is just a no-op, matching what
--detect-types already does for a zero-byte CSV (no header either).
Closes simonw#702.
Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the CSV has a header but no data rows, the insert path never creates the table — the row loop has nothing to feed into the first insert. The post-insert `tracker.transform()` call then asserts the table exists and blows up:
Reported in #702 with the exact fix in the issue body. Guarded the transform on `db[table].exists()` so an empty CSV becomes a no-op — matching the behavior for a zero-byte CSV (no header either).
Added a parameterized test (both `-d` and `--detect-types`) so we don't regress.
Closes #702.
📚 Documentation preview 📚: https://sqlite-utils--739.org.readthedocs.build/en/739/