Fixed bug with sqlite-utils upsert --detect-types, closes #362

This commit is contained in:
Simon Willison 2022-01-05 22:28:29 -08:00
commit a7b29bfaa9
2 changed files with 19 additions and 0 deletions

View file

@ -1045,6 +1045,7 @@ def upsert(
not_null=not_null,
default=default,
encoding=encoding,
detect_types=detect_types,
load_extension=load_extension,
silent=silent,
)

View file

@ -1974,6 +1974,24 @@ def test_insert_detect_types(tmpdir, option_or_env_var):
_test()
@pytest.mark.parametrize("option", ("-d", "--detect-types"))
def test_upsert_detect_types(tmpdir, option):
db_path = str(tmpdir / "test.db")
data = "id,name,age,weight\n1,Cleo,6,45.5\n2,Dori,1,3.5"
result = CliRunner().invoke(
cli.cli,
["upsert", db_path, "creatures", "-", "--csv", "--pk", "id"] + [option],
catch_exceptions=False,
input=data,
)
assert result.exit_code == 0
db = Database(db_path)
assert list(db["creatures"].rows) == [
{"id": 1, "name": "Cleo", "age": 6, "weight": 45.5},
{"id": 2, "name": "Dori", "age": 1, "weight": 3.5},
]
@pytest.mark.parametrize(
"input,expected",
(