Raise ValueError instead of assert for conflicting insert_all() options#753
Open
IgnazioDS wants to merge 1 commit into
Open
Raise ValueError instead of assert for conflicting insert_all() options#753IgnazioDS wants to merge 1 commit into
IgnazioDS wants to merge 1 commit into
Conversation
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.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
insert_all()validates two mutually-exclusive argument pairs —pk=/hash_id=andignore=/replace=— with bareassertstatements:Two problems:
assertstatements 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.AssertionError, which is inconsistent with the neighbouring validation a couple of lines above that raisesPrimaryKeyRequired/ValueErrorfor the same kind of argument problem.This replaces both asserts with explicit
ValueErrorraises (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/flake8clean.📚 Documentation preview 📚: https://sqlite-utils--753.org.readthedocs.build/en/753/