sqlite-utils/tests
feiiiiii5 210c119907
insert --convert: validate the result instead of falling back on falsy
The JSON/CSV branch used 'fn(doc) or doc', so any falsy result was
discarded and the unconverted row inserted. Exit code 0, no warning:

    $ echo '[{"id": 1, "name": "Cleo"}]' | sqlite-utils insert d.db t - --convert '{}'
    $ sqlite-utils 'select * from d.db'      # -> the original row, not {}

The realistic shape of this is a filter:

    --convert 'row if row["ok"] else {}'    # meant to drop the bad rows
    # every row inserted, including the ones meant to be dropped

'--lines' runs a different expression twelve lines up and has no such
fallback, so the same --convert code is rejected there and silently
accepted here:

    --convert 0   JSON input  -> exit 0, rows inserted
    --convert 0   --lines     -> exit 1, Rows must all be dictionaries, got: 0

test_insert_convert_error_messages already asserts that a non-dict
return is rejected (--convert 1); 0, False, [] and "" were the outliers,
purely because they are falsy.

None is the one falsy result that has to keep meaning 'modify doc in
place' - a --convert that is a bare statement returns it, which
test_insert_convert_row_modifying_in_place covers - so the fallback is
now keyed on 'is None' rather than truthiness.

Tests: 7 new cases in tests/test_cli_insert.py, all failing on 6bc1d33.
Suite 1505 passed, 16 skipped. black, flake8, mypy clean. pyright
reports one error and ty two diagnostics, both identical on unmodified
main (tests/test_constructor.py:74 and two unused-type-ignore comments
in db.py/utils.py) and none in the files this touches.
2026-09-29 00:24:06 +08:00
..
sniff sqlite-utils insert --sniff option, closes #230 2021-02-14 11:23:12 -08:00
__init__.py Initial project layout + database table creation tools 2018-07-28 06:46:17 -07:00
conftest.py Fixes for Ruff>=0.16.0 (#814) 2026-07-25 14:53:12 -07:00
ext.c Support entrypoints for --load-extension (#473) 2022-08-26 22:55:47 -07:00
test_analyze.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_analyze_tables.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_atomic.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_attach.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_cli.py Support ANY column types for strict tables 2026-08-12 16:44:01 -07:00
test_cli_bulk.py Fixes for Pyright, closes #833 2026-08-12 14:03:04 -07:00
test_cli_convert.py Use quoted SQL identifiers in convert --dry-run, closes #829 2026-08-12 14:14:27 -07:00
test_cli_insert.py insert --convert: validate the result instead of falling back on falsy 2026-09-29 00:24:06 +08:00
test_cli_memory.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_cli_migrate.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_column_affinity.py Support ANY column types for strict tables 2026-08-12 16:44:01 -07:00
test_column_casing.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_constructor.py Fixes for Pyright, closes #833 2026-08-12 14:03:04 -07:00
test_conversions.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_convert.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_create.py Support ANY column types for strict tables 2026-08-12 16:44:01 -07:00
test_create_table_parser.py Preserve composite UNIQUE constraints in transforms 2026-08-12 18:46:18 -07:00
test_create_view.py Fixes for Ruff>=0.16.0 (#814) 2026-07-25 14:53:12 -07:00
test_default_value.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_delete.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_docs.py Fixes for Ruff>=0.16.0 (#814) 2026-07-25 14:53:12 -07:00
test_duplicate.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_enable_counts.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_extract.py Support ANY column types for strict tables 2026-08-12 16:44:01 -07:00
test_extracts.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_foreign_keys.py Fixes for Pyright, closes #833 2026-08-12 14:03:04 -07:00
test_fts.py Fixes for Pyright, closes #833 2026-08-12 14:03:04 -07:00
test_get.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_gis.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_hypothesis.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_insert_files.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_introspect.py Fixed introspection of default values TRUE / FALSE / NULL 2026-08-12 14:19:38 -07:00
test_list_mode.py Fixes for Pyright, closes #833 2026-08-12 14:03:04 -07:00
test_lookup.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_m2m.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_migrations.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_mutator_transactions.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_plugins.py Fixes for Ruff>=0.16.0 (#814) 2026-07-25 14:53:12 -07:00
test_query.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_recipes.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_recreate.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_register_function.py Fixes for Pyright, closes #833 2026-08-12 14:03:04 -07:00
test_rows.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_rows_from_file.py Fix resource leaks caused by buffered readers 2026-09-22 11:35:41 -07:00
test_sniff.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_suggest_column_types.py Fixes for Ruff>=0.16.0 (#814) 2026-07-25 14:53:12 -07:00
test_tracer.py Fixes for Ruff>=0.16.0 (#814) 2026-07-25 14:53:12 -07:00
test_transform.py transform: coerce empty strings to NULL when converting TEXT columns to numeric types (#805) 2026-08-13 12:56:51 -07:00
test_update.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00
test_upsert.py Fixes for Pyright, closes #833 2026-08-12 14:03:04 -07:00
test_utils.py Fixes for Ruff>=0.16.0 (#814) 2026-07-25 14:53:12 -07:00
test_wal.py Use db.table() and db.view() in tests, closes #838 2026-08-12 14:03:04 -07:00