This is an automated email from the ASF dual-hosted git repository.
joao-r-reis pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra-gocql-driver.git
The following commit(s) were added to refs/heads/trunk by this push:
new 87d836cd Handle null UUID columns when unmarshaling into *[16]byte and
*time.Time
87d836cd is described below
commit 87d836cd8df6932df8a681fa76f74109be7885a8
Author: xiaonan chen <[email protected]>
AuthorDate: Wed Sep 9 00:00:02 2026 +0800
Handle null UUID columns when unmarshaling into *[16]byte and *time.Time
Unmarshaling a null (empty) uuid/timeuuid value into *[16]byte returned
an error instead of setting the zero value, unlike the other supported
target types. Similarly, timeUUIDType.Unmarshal passed empty data to
UUIDFromBytes for *time.Time, failing with "UUIDs must be exactly 16
bytes long". Both now set the zero value, consistent with the other
null-data branches. The unmarshal error messages now also list *[16]byte
among the accepted types. Added table-driven test cases covering these
paths.
Patch by xiaonan chen; reviewed by worryg0d, João Reis for CASSGO-134
---
marshal.go | 10 ++++++++--
marshal_test.go | 18 ++++++++++++++++++
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/marshal.go b/marshal.go
index 972ed2f0..fb171750 100644
--- a/marshal.go
+++ b/marshal.go
@@ -2251,10 +2251,12 @@ func uuidUnmarshal(kind string, data []byte, value
interface{}) error {
*v = nil
case *UUID:
*v = UUID{}
+ case *[16]byte:
+ *v = UUID{}
case *interface{}:
*v = UUID{}
default:
- return unmarshalErrorf("can not unmarshal %s into %T.
Accepted types: *UUID, *[]byte, *string, *interface{}.", kind, value)
+ return unmarshalErrorf("can not unmarshal %s into %T.
Accepted types: *UUID, *[16]byte, *[]byte, *string, *interface{}.", kind, value)
}
return nil
@@ -2291,7 +2293,7 @@ func uuidUnmarshal(kind string, data []byte, value
interface{}) error {
*v = u[:]
return nil
}
- return unmarshalErrorf("can not unmarshal %s into %T. Accepted types:
*UUID, *[]byte, *string, *interface{}.", kind, value)
+ return unmarshalErrorf("can not unmarshal %s into %T. Accepted types:
*UUID, *[16]byte, *[]byte, *string, *interface{}.", kind, value)
}
type timeUUIDType struct{}
@@ -2319,6 +2321,10 @@ func (t timeUUIDType) Marshal(value interface{})
([]byte, error) {
func (t timeUUIDType) Unmarshal(data []byte, value interface{}) error {
switch v := value.(type) {
case *time.Time:
+ if len(data) == 0 {
+ *v = time.Time{}
+ return nil
+ }
id, err := UUIDFromBytes(data)
if err != nil {
return err
diff --git a/marshal_test.go b/marshal_test.go
index 55b70dd1..4f6afb8d 100644
--- a/marshal_test.go
+++ b/marshal_test.go
@@ -1322,6 +1322,24 @@ var unmarshalTests = []struct {
}(),
nil,
},
+ {
+ uuidType{},
+ []byte(nil),
+ [16]byte{},
+ nil,
+ },
+ {
+ timeUUIDType{},
+ []byte(nil),
+ [16]byte{},
+ nil,
+ },
+ {
+ timeUUIDType{},
+ []byte(nil),
+ time.Time{},
+ nil,
+ },
}
func decimalize(s string) *inf.Dec {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]