Repository navigation
Conversation
JSONSelection and JSONRead had no driver.Valuer Value method. When a program passed one as a query parameter, pgx bound the text that String returns. That text is redacted. A JSONSelection then matched no rows and returned no error. A JSONRead failed with a malformed array literal. Each type now has a Value method that returns its operand's own Value: the selector as text, and the tokens as a text[] literal. A zero selection or read is refused, as a zero selector or empty tokens are. JSONChildren already bound its token in the same way. Refs #1849 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
cipherstash-agent
left a comment
There was a problem hiding this comment.
Review attestation
Reviewed 75e2d16 · posted from Claude Code (scheduled routine) · claude-opus-5-5 · effort medium
Sources: code-review · claude-opus-5-5; mattpocock-skills:code-review (Standards and Spec sub-agents) · claude-opus-5-5
Skills: code-review, mattpocock-skills:code-review, company-skills:review-cross-check; company-skills:rust-security was loaded but does not apply to this Go-only change
Findings (4): 4 minor — 4 inline, 0 below.
Each finding was verified at 75e2d16 by company-skills:review-cross-check. Two candidate findings were refuted there and are not posted: CI does run TestJSONDocumentsQueryAndReadInPostgres (through go:test:postgres → the EQL conformance lane, which passed on this commit), and the three one-line Value methods delegate to operands of different types, so they share no logic to extract. The fix itself (JSONSelection.Value, JSONRead.Value) is correct. No tests were run by this review.
Generated by Claude Code
Review found four small problems in the previous commit: - The new test sat between TestJSONReadTypesPrintAndLogRedacted and its doc comment. The comment now sits above its own test again. - The new test's comment said that a JSONRead bound as its String form matches no row. It fails with a malformed array literal instead. - The new test's comment also said that database/sql always applies the default converter. pgx skips that converter and calls the driver.Valuer itself. The comment now says which path each test covers. - The stashgen README did not say that a JSONChildren binds as its token, and the encrypt README paragraph was not re-wrapped. Refs #1849 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk
|
@coderabbitai review |
Action performed
|
Summary
In the Go SDK, a program can now pass a
JSONSelectionstraight to a query as a parameter. The query then finds the right rows. Before this fix, the query matched no rows and returned no error.JSONReadhad the same gap, and this pull request fixes it too.A
JSONSelectioncontains the selector for a JSON path query (col -> $1::text). AJSONReadcontains the tokens for a subtree read (eql_v4.json_tree_subtree(col, $1::text[])). Neither type had aValuemethod. That method is thedriver.Valuerinterface, anddatabase/sqluses it to turn a Go value into a query parameter. So pgx bound the text that the type'sStringmethod returns. That text is redacted, so that a selector or a token never appears in a log.JSONSelectionbound that way matched no rows, and the query returned no error.JSONReadbound that way failed withmalformed array literal.Binding
.Selector()or.Tokens()worked before this fix, and still works.Changes
SDK (
encrypt/json.go):JSONSelection.Valuereturns the selector as text.JSONRead.Valuereturns the tokens as atext[]literal. Each one calls theValuemethod its operand already has, asJSONChildren.Valuealready did. A zero selection or read is refused withErrEncoding, as a zero selector or empty tokens are. Both methods use a value receiver, so a value and a pointer both bind.Tests (
encrypt/json_fields_test.go): a new test,TestJSONSelectionAndReadBindAsTheirOperand. For a value and a pointer of each type, it checks these things:driver.ValuerValue()returns the operanddatabase/sqlapplies (driver.DefaultParameterConverter) gives the operand, not the redacted textIt also checks that a zero value of each type is refused.
Tests (
encrypt/json_postgres_test.go):TestJSONDocumentsQueryAndReadInPostgresnow binds the selection itself and the read itself, and checks the rows each query returns.Docs: a
CHANGELOG.mdentry under Unreleased, and a note inencrypt/README.mdandcmd/stashgen/README.mdthat each type binds as its operand.Verification
New unit test, without the fix: it did not compile, because
Valuewas undefined. With the zero-value checks left out, all four subtests failed with... is not a driver.Valuer. With the fix, all four pass.PostgreSQL test: I ran it against PostgreSQL 17 with EQL v4 installed.
mise run go:test:postgresdoes not run on my machine: it installssqlx-cli. That build needs OpenSSL development headers, and the machine does not have them. So I did its steps by hand:MISE_DISABLE_TOOLS=cargo:sqlx-cli,cargo:cargo-expand mise -C packages/eql run build.postgres:17container.packages/eql/release/cipherstash-encrypt-v4.sqlinto it withpsql.go test -run '^TestJSONDocumentsQueryAndReadInPostgres$' ./encryptwithDATABASE_URLset to that container.Without the fix, the test failed in the way the issue describes:
age < 40, the selection bound: rows [], want [1 2]ERROR: malformed array literal: "encrypt.JSONRead{field: "profile", path: [redacted], tokens: 65}"With the fix, it passes.
Full suite:
CGO_ENABLED=0 go test -timeout=25m -count=1 ./encrypt/...withDATABASE_URLset: every package passes.Race detector:
go test -racepasses for./encrypt/...(all but./encryptitself),./stashgen/...and./cmd/.... For./encrypt, it passes for every JSON, PostgreSQL, and customer-field test. A whole-package race run of./encrypthit Go's default 10-minute timeout, because the WebAssembly guests run slowly under the race detector. CI does not run this module with-race.Lint:
gofmt -l .printed nothing,go vet ./encrypt/...passed, andgolangci-lint run ./encrypt/reported 0 issues.Generated code:
go generate ./...changed no file.No live CipherStash credentials were used. The tests use the deterministic guest builds.
Related
Closes #1849
Review notes
I checked the other types a program might pass as a parameter.
JSONChildren,JSONSelector,JSONToken,JSONTokens, the term types, and the query types already have aValuemethod.JSONRangeandRangeeach contain two bounds that bind as two parameters, so they need noValuemethod.🤖 Generated with Claude Code
https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk
Summary by CodeRabbit