Fix raw_values mutation that broke repeated raw= searches#56
Open
roed-math wants to merge 1 commit into
Open
Conversation
search() and lucky() had a mutable default raw_values=[], and _build_query aliased that list (values = raw_values) before appending the limit and offset. As a result the first raw= search in a process worked, but every subsequent one inherited the accumulated limit/offset values and failed with "TypeError: not all arguments converted during string formatting" (the query had fewer %s placeholders than values). A caller-supplied raw_values list was likewise mutated as a side effect. Copy raw_values in _build_query so the caller's list is never mutated, and change the mutable defaults in search()/lucky() to None. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
The bug
search()andlucky()declare a mutable defaultraw_values=[], and_build_queryaliases that list before appending the limit/offset:So the first
raw=search in a process works, but every subsequent one inherits the accumulatedlimit/offsetfrom the shared default list. The generated SQL then has fewer%splaceholders than values, and the query dies with:A caller that passes its own
raw_valueslist is also affected — the list is mutated as a side effect of the search.Reproduce
The fix
raw_valuesin_build_query(values = list(raw_values)) so the caller's list is never mutated.search()andlucky()from[]toNone(_build_queryalready coalescesNoneto[]).After the fix, repeated
raw=searches succeed and a caller-suppliedraw_valueslist is left untouched. Added a doctest in_build_querydemonstrating both.(Found while adding a command-line raw-SQL search to the LMFDB.)
🤖 Generated with Claude Code