]> Cypherpunks repositories - gostls13.git/commit
database/sql: ensure Null* types have Valid=false when Scan returns error
authorRavi Sastry Kadali <ravisastryk@gmail.com>
Mon, 26 Jan 2026 02:29:30 +0000 (18:29 -0800)
committerGopher Robot <gobot@golang.org>
Fri, 6 Feb 2026 20:10:59 +0000 (12:10 -0800)
commit9263a71b92e84aa34d0e35887d5c23f5a0a21537
tree82d3b4c216b4d0b8ebaa8278e8fe916550d4e49e
parent0430fa977573866f93e66aa61a66b37ff0738aba
database/sql: ensure Null* types have Valid=false when Scan returns error

The Scan methods for NullString, NullInt64, NullInt32, NullFloat64,
NullBool, and NullTime set Valid=true before calling convertAssign.
If convertAssign returns an error, Valid remains true, which creates
an inconsistent state where Valid=true but err!=nil.

Fix by setting Valid only after successful conversion.

Fixes #45662

Change-Id: I855a20abbe517ed017f7c9b8f5603b17bd9d487d
Reviewed-on: https://go-review.googlesource.com/c/go/+/739160
Auto-Submit: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/database/sql/sql.go
src/database/sql/sql_test.go