From bdee62b0d502be2b6398b05b28d36ff8cf86dafb Mon Sep 17 00:00:00 2001 From: sylwiaszunejko Date: Wed, 5 Jun 2024 13:57:55 +0200 Subject: [PATCH] Marshal missing UDT fields as null instead of failing We can't return an error in case a field is added to the UDT, otherwise existing code would break by simply altering the UDT in the database. For extra fields at the end of the UDT put nulls to be in line with gocql, but also python-driver and java-driver. In gocql it was fixed in https://github.com/scylladb/gocql/commit/d2ed1bb74f3118a83a352e9ce912be765001efa4 --- udt.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/udt.go b/udt.go index e17ac06..a874989 100644 --- a/udt.go +++ b/udt.go @@ -39,11 +39,17 @@ func makeUDT(value reflect.Value, mapper *reflectx.Mapper, unsafe bool) udt { func (u udt) MarshalUDT(name string, info gocql.TypeInfo) ([]byte, error) { value, ok := u.field[name] - if !ok { - return nil, fmt.Errorf("missing name %q in %s", name, u.value.Type()) + + var data []byte + var err error + if ok { + data, err = gocql.Marshal(info, value.Interface()) + if err != nil { + return nil, err + } } - return gocql.Marshal(info, value.Interface()) + return data, err } func (u udt) UnmarshalUDT(name string, info gocql.TypeInfo, data []byte) error {