sqlite-utils icon indicating copy to clipboard operation
sqlite-utils copied to clipboard

Raise ValueError instead of assert for conflicting insert_all() options

Open IgnazioDS opened this issue 5 months ago • 1 comments

insert_all() validates two mutually-exclusive argument pairs — pk=/hash_id= and ignore=/replace= — with bare assert statements:

assert not (hash_id and pk), "Use either pk= or hash_id="
...
assert not (ignore and replace), "Use either ignore=True or replace=True, not both"

Two problems:

  1. assert statements are stripped when Python runs under -O/-OO, so on optimized deployments these checks vanish entirely and a contradictory call (e.g. insert_all(rows, pk="id", hash_id="hash")) silently proceeds instead of being rejected.
  2. When they do fire they raise AssertionError, which is inconsistent with the neighbouring validation a couple of lines above that raises PrimaryKeyRequired / ValueError for the same kind of argument problem.

This replaces both asserts with explicit ValueError raises (same messages) and adds regression tests for the two conflicts. No behaviour change for valid calls.

Full test suite passes (1042 passed, 16 skipped); black/flake8 clean.


📚 Documentation preview 📚: https://sqlite-utils--753.org.readthedocs.build/en/753/

IgnazioDS avatar Jun 10 '26 06:06 IgnazioDS

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Fixed in the latest RC.

simonw avatar Jul 05 '26 20:07 simonw