mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-25 11:24:12 +02:00
Raise ValueError instead of assert for conflicting insert_all() options
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.
This commit is contained in:
parent
8f0c06e188
commit
04701e5bca
2 changed files with 24 additions and 4 deletions
|
|
@ -3464,15 +3464,15 @@ class Table(Queryable):
|
|||
if upsert and (not pk and not hash_id):
|
||||
raise PrimaryKeyRequired("upsert() requires a pk")
|
||||
|
||||
assert not (hash_id and pk), "Use either pk= or hash_id="
|
||||
if hash_id and pk:
|
||||
raise ValueError("Use either pk= or hash_id=")
|
||||
if hash_id_columns and (hash_id is None):
|
||||
hash_id = "id"
|
||||
if hash_id:
|
||||
pk = hash_id
|
||||
|
||||
assert not (
|
||||
ignore and replace
|
||||
), "Use either ignore=True or replace=True, not both"
|
||||
if ignore and replace:
|
||||
raise ValueError("Use either ignore=True or replace=True, not both")
|
||||
all_columns = []
|
||||
first = True
|
||||
num_records_processed = 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue