Skip to content

Raise ValueError instead of assert for conflicting insert_all() options#753

Open
IgnazioDS wants to merge 1 commit into
simonw:mainfrom
IgnazioDS:fix-insert-all-assert-validation
Open

Raise ValueError instead of assert for conflicting insert_all() options#753
IgnazioDS wants to merge 1 commit into
simonw:mainfrom
IgnazioDS:fix-insert-all-assert-validation

Conversation

@IgnazioDS

@IgnazioDS IgnazioDS commented Jun 10, 2026

Copy link
Copy Markdown

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/

insert_all() validated the pk=/hash_id= and ignore=/replace= argument
conflicts with bare assert statements. Asserts are stripped under
`python -O`, so the validation silently disappears in optimized
deployments, and when they do fire they raise AssertionError rather than
the ValueError used for the neighbouring pk validation. Replace both
with explicit ValueError raises and add regression tests.
@chatgpt-codex-connector

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant