Skip to content

Interpolate typed-nil json.RawMessage as NULL#1782

Merged
methane merged 1 commit into
go-sql-driver:masterfrom
oha-4:fix-json-rawmessage-nil-interpolate
Jul 15, 2026
Merged

Interpolate typed-nil json.RawMessage as NULL#1782
methane merged 1 commit into
go-sql-driver:masterfrom
oha-4:fix-json-rawmessage-nil-interpolate

Conversation

@oha-4

@oha-4 oha-4 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #1781.

When interpolateParams=true, a typed-nil json.RawMessage (for example a nil json.RawMessage carried inside a driver.Value/interface{}) was interpolated as an empty quoted string ('') instead of NULL. Inserting that into a JSON column made the server reject it with Error 3140 (invalid JSON text value).

The typed nil passes the initial untyped-nil check and reaches the case json.RawMessage: branch in interpolateParams (connection.go), which escaped/quoted the value unconditionally. The adjacent case []byte: branch already guards for nil and emits NULL; this change adds the same guard so json.RawMessage(nil) is interpolated as NULL, matching the server-side prepared-statement path (interpolateParams=false).

Checklist

  • Code compiles correctly
  • Created tests which fail without the change (TestInterpolateParamsJSONRawMessageNil)
  • All tests passing
  • Extended the README / documentation, if necessary (not needed)
  • Added myself / the copyright holder to the AUTHORS file

@oha-4
oha-4 marked this pull request as ready for review July 15, 2026 03:14
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0a477201-c99d-49b1-828d-82acc73abf35

📥 Commits

Reviewing files that changed from the base of the PR and between 05c8065 and f179909.

📒 Files selected for processing (3)
  • AUTHORS
  • connection.go
  • connection_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • AUTHORS
  • connection.go

Walkthrough

interpolateParams now emits NULL for typed nil json.RawMessage values, with a regression test. The AUTHORS file also adds Yoshito Ohata.

Changes

JSON interpolation fix

Layer / File(s) Summary
Nil JSON interpolation
connection.go, connection_test.go
Nil json.RawMessage parameters now produce SELECT NULL, covered by a dedicated test.

Author record update

Layer / File(s) Summary
Add author entry
AUTHORS
Adds Yoshito Ohata and the provided email address.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: interpolating typed-nil json.RawMessage as NULL.
Description check ✅ Passed The description matches the implemented fix and the added regression test.
Linked Issues check ✅ Passed The change satisfies #1781 by emitting NULL for nil json.RawMessage during interpolation and preserving behavior elsewhere.
Out of Scope Changes check ✅ Passed No clear out-of-scope code changes are present beyond the requested fix and its regression test.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

When interpolateParams=true, a typed-nil json.RawMessage (e.g. a nil
json.RawMessage stored in an interface) was interpolated as an empty
quoted string ('') instead of NULL. Inserting it into a JSON column made
the server reject it with Error 3140 (invalid JSON text).

The json.RawMessage case in interpolateParams lacked the nil guard that
the adjacent []byte case already has. Add the same guard so a nil value
is emitted as NULL, matching the server-side prepared statement path
(interpolateParams=false).

Fixes go-sql-driver#1781

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@oha-4
oha-4 force-pushed the fix-json-rawmessage-nil-interpolate branch from 05c8065 to f179909 Compare July 15, 2026 03:19
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 82.544% (-0.09%) from 82.633% — oha-4:fix-json-rawmessage-nil-interpolate into go-sql-driver:master

@methane
methane merged commit b96d415 into go-sql-driver:master Jul 15, 2026
38 checks passed
@oha-4
oha-4 deleted the fix-json-rawmessage-nil-interpolate branch July 16, 2026 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

interpolateParams: a nil json.RawMessage is sent as '' instead of NULL (Error 3140)

3 participants