googleapis / go-sql-spanner

Google Cloud Spanner driver for Go's database/sql package.
Apache License 2.0
104 stars 24 forks source link

Passing nil to pointers of types that implement driver.Valuer via value receivers panics #295

Closed drewthor closed 1 month ago

drewthor commented 1 month ago

When a type defines a value receiver Value() method implementing database/sql's driver.Valuer interface, and nil is passed as a pointer to that type as a query parameter go-sql-spanner panics inside CheckNamedValue with an error of panic: value method github.com/googleapis/go-sql-spanner.ValuerNil.Value called using nil *CustomType pointer.

This is a special case, however the database/sql package handles this case gracefully and if it detects this case will pass along nil as the value to the database. See https://github.com/golang/go/commit/0ce1d79a6a771f7449ec493b993ed2a720917870#diff-d55a0593e9a7f78d72c435734e71154a20e8c22feec63f09cfbf00e8ba498daeR211-R232/https://go-review.googlesource.com/c/go/+/31259 and https://github.com/golang/go/issues/8415 for discussion.