Repository navigation
Bind QueryService filter values as parameters instead of interpolating them - #2751
Conversation
Pragmatic Code Review — PR #2751Review Type: Initial Review Requirements CheckFrom issue #2744:
📝 The PR body's note that the quote test originally used Code Review FindingsI went looking for the failure modes this refactor class usually has, and did not find them. Below is what I verified rather than a list of problems. Verified — no findingsPlaceholder/param correspondence cannot drift. The I specifically checked the ordering concern — conditions are accumulated into a Type mapping in The bool-as-integer mapping was the highest-risk item and it checks out. I confirmed against SQLite 3.46 that NULL comparison semantics are unchanged.
Index coupling holds, including with the newly-bound This one deserved real scrutiny, because binding The LIKE quote-doubling removal is correct, and the reasoning in the PR body is sound. I reproduced all three variants against SQLite directly, searching for
Leaving the doubling in would have silently broken every apostrophe search — no error, just zero results. Removing it restores exactly the pre-refactor behavior. The distinction the comment draws (quote-doubling is syntax, subsumed by binding; wildcard escaping is pattern semantics, still needed) is precise and worth keeping in the docstring, which it is. Relationship filter refactor preserves every column mapping. Checked each arm against the deleted originals in the diff: Children LIMIT left unbound is justified.
Project standards. No lint suppressions, no 🟢 Suggestion📁 Two assertions hardcode placeholder numbers: The Principle (tests should fail for one reason): consider relaxing the second to a regex or Test quality assessmentThe five new tests are real, not ceremonial. Three of them (
📝 Minor observation, not a finding: nothing covers RecommendationAPPROVE This is a clean, well-motivated structural refactor that does exactly what issue #2744 asked and nothing more. The Two things raise my confidence above the usual for a change in this area. First, the one deliberate behavior change (dropping quote-doubling from The single suggestion above is a nit about test brittleness and should not gate the merge. Verification run: |
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
Review ResponseOne recommendation in the review (🟢 Suggestion, hardcoded placeholder numbers). Addressed one of the two call sites, kept the other deliberately — the reviewer's own analysis is what splits them. ✅ Addressed —
|
…g them (closes #2744) QueryService built its WHERE clause by formatting operands into the SQL string, with safety resting on `escape_string` doubling single quotes at every call site. That was correct, but correct-by-audit: each new operator was a fresh chance to interpolate a value without escaping it, and nothing in the type system would have caught it. Values now reach SQL as bound parameters. `BoundSql` carries the statement and its parameter vector, and its `bind` is the only way to place a value: it pushes the value and returns the matching `?N` in one step, so a placeholder cannot exist without its value and the numbering cannot drift. `format_value` and `escape_string` are gone. Identifier positions are unchanged — SQL cannot bind a table, column or JSON path segment, so those are still interpolated and still arrive allowlisted by `query_ops::validate_identifier`. `escape_string_for_like` keeps its job but loses its quote-doubling. LIKE wildcard escaping is about pattern semantics, not SQL syntax: binding stops a value being read as SQL but not as a pattern, so `%` and `_` still need escaping. Quote-doubling was syntax, which binding subsumes — leaving it in would have matched a literal doubled quote. The LIKE pattern's own `%` delimiters are now concatenated in SQL rather than wrapped around an interpolated string. `query_node_ids_raw` takes a parameter vector alongside the SQL. Five new tests cover the boundary; each was verified to fail against the previous implementation: - property filters and relationship subqueries emit placeholders and bind - IN generates one placeholder per member, numbered consecutively - a value containing a quote is matched literally, via free text rather than the validated `task.status` enum - non-string operands bind as their SQLite counterparts (bool as 0/1) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
561cdbe to
66edbfd
Compare
Rebased onto main — conflict with #2749, and it needed a real decision
The conflict#2749 extracted The two are complementary, and the resolution is better than either side alone: This matters beyond fixing the conflict. Taking #2749's side verbatim would have left Consequent changes not in the reviewed diff
Verification
📝 One note for the record: the first push attempt failed the gate on a frontend test. This change is Rust-only, and Re-review: I'd suggest yes. The reviewed diff was test-only-since-approval, but this rebase changed production code — a new signature on |
Pragmatic Code Review — RE-REVIEWReview Type: Re-Review (post-rebase onto Previous Review Summary
The post-review fix survived the rebase verbatim. Requirements Check — issue #2744 (re-verified post-rebase)
Every criterion still met after the rebase. Rebase Integration AssessmentVerdict: the resolution is correct, complete, and faithful to both PRs' invariants. The net production delta versus the previously-approved commit 1. Is the count path actually bound? ✅ Yes, end to end. 2. Do select and count still match? ✅ Yes, and the sharing is what guarantees it. Both callers take the whole built.sql = format!("SELECT * FROM node{}", built.sql); // build_query
built.sql = format!("SELECT COUNT(*) FROM node{};", built.sql); // build_count_query
Mutation-verified. I temporarily added
The mutation was reverted; 3. Placeholder numbering across the two callers. ✅ No off-by-one, and no path can bind ahead of the clause. On whether the doc-comment constraint ("a caller must not bind anything of its own ahead of this clause") is enforced or merely documented: it is enforced by construction for the current callers — neither holds a 4. 5. Modified tests from #2749 — faithful, and strictly stronger. ✅ 6. Did any of #2749's test coverage get lost? ✅ No. This was the flagged highest-risk area, so I checked it mechanically rather than by reading. Extracting every
The test-file diff against main is additions plus exactly three signature-forced modifications (the 7. Regressions in previously-approved work. ✅ None. All 5 binding tests plus the 2 added later survived; the Re-confirmed spot checks:
On the frontend gate flake: I found no evidence it was real. This branch's net diff versus main is three Rust files ( Verification Run
Code Review Findings🔴 CriticalNone. 🟡 ImportantNone. 🟢 Suggestions
This is pre-existing (the asymmetry arrived with #2749, not with this PR) and genuinely optional — it is a one-word change with no behavioral effect, and leaving it does not block anything. Flagging it because this PR is what made the two contracts identical, so it is the natural moment. Equally fine to file separately or skip. Nit: AssessmentThis is a textbook conflict resolution. The temptation in a rebase like this is to take one side and move on; the resolution instead identified that doing so would have left The highest-risk part of the resolution — the wholesale-take-and-re-append on the test file — verified clean under mechanical comparison: zero tests from either parent were lost. The doc comments were updated rather than left stale, including the Net effect on code health is strongly positive: RecommendationAPPROVE — no blocking findings. The one 🟢 Suggestion is optional and pre-existing. |
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review (re-review): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
The re-review flagged that `query_node_ids_raw` is `pub` while its counterpart `count_nodes_raw` is `pub(crate)`, now that both carry an identical contract. Taking it despite being flagged optional and pre-existing, because this PR is what made the contracts identical: both bind their values, leaving only identifier positions to the caller. The comment written here in this PR says "Same contract as that method" — so the asymmetric visibility is an inconsistency this PR introduced, and it reads as accident rather than decision. `QueryService` is the only caller of either, and both call sites are in-crate, so the compiler now enforces the audit boundary that the sibling's comment argues for. Verified by `cargo check --workspace --all-targets`, which is what proves no out-of-crate caller existed rather than a grep asserting it. The nit about `execute_query_for_ids` cloning `params` while `count` moves it is left alone: it is forced by the `&BoundSql` receiver, and changing the receiver to satisfy a cosmetic asymmetry would be the tail wagging the dog. Severity: 🟢 Suggestion Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Re-Review ResponseOne 🟢 Suggestion from the re-review. Applied, despite it being flagged optional and pre-existing. ✅ Narrowed
|
Closes #2744.
What changed
QueryServicebuilt its WHERE clause by formatting operands into the SQL string, with safety resting onescape_stringdoubling single quotes at every call site. As the issue notes, that was correct — but correct-by-audit: every new operator was a fresh chance to interpolate a value without escaping it, and nothing in the type system would have caught it.Values now reach SQL as bound parameters. A small
BoundSqlstruct carries the statement and its parameter vector, and itsbindis the only way to place a value: it pushes the value and returns the matching?Nin the same step. A placeholder cannot exist without its value, and a value cannot be supplied without the numbering advancing, so the two cannot drift.format_valueandescape_stringare deleted.The four points the issue flagged for confirmation
execute_query_for_ids—query_node_ids_rawnow takes a parameter vector alongside the SQL.IN— generates one placeholder per member, numbered consecutively.query_ops::validate_identifier. Every caller funnels throughexecute_query_nodes, which validates.escape_string_for_like— keeps its job but loses its quote-doubling, which is the one real behavior change here. Wildcard escaping is LIKE pattern semantics: binding stops a value being read as SQL, but not as a pattern, so%and_still need escaping. Quote-doubling was syntax, which binding subsumes — leaving it in would have made acontainssearch forit'smatch a literal doubled quote and find nothing.The LIKE pattern's own
%delimiters are now concatenated in SQL (LOWER(x) LIKE LOWER('%' || ?1 || '%')) rather than wrapped around an interpolated string.build_property_filter's output still starts with the exact expressionidx_task_statusis built on, so the index-coupling tests hold and filters keep using their indexes.LIMITstays formatted rather than bound — ausizehas no string representation SQL could misinterpret, and it keeps the limit visible to the query planner.Testing
Five new tests, and each was verified to fail against the previous implementation by reverting the binding and re-running:
INgenerates one placeholder per membercontainsvalue stay literalWorth noting: the quote test initially used
task.status, which is a validated enum that rejected the quoted value before it ever reached SQL — so the test was green while proving nothing. It now uses free-text content.All 1573 Rust lib tests pass (existing coverage unchanged, as the issue asked).
quality:fixclean including clippy under-D warnings. Full pre-push gate green.🤖 Generated with Claude Code