mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-18 22:44:10 +02:00
Skip type detection when CSV insert created no table
Closes #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>
This commit is contained in:
parent
8f0c06e188
commit
0c5e9eb104
2 changed files with 19 additions and 2 deletions
|
|
@ -2296,6 +2296,21 @@ def test_insert_detect_types(tmpdir, option):
|
|||
]
|
||||
|
||||
|
||||
def test_insert_detect_types_header_only_csv(tmpdir):
|
||||
"""A CSV that is only a header row creates no table; --detect-types should
|
||||
not crash trying to transform it. Regression for #702."""
|
||||
db_path = str(tmpdir / "test.db")
|
||||
result = CliRunner().invoke(
|
||||
cli.cli,
|
||||
["insert", db_path, "creatures", "-", "--csv", "--detect-types"],
|
||||
catch_exceptions=False,
|
||||
input="name,age,weight\n",
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
db = Database(db_path)
|
||||
assert "creatures" not in db.table_names()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("option", (None, "-d", "--detect-types"))
|
||||
def test_upsert_detect_types(tmpdir, option):
|
||||
"""Test that type detection is now the default behavior for upsert"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue