Skip to content

Commit

Permalink
Marshal missing UDT fields as null instead of failing
Browse files Browse the repository at this point in the history
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 scylladb/gocql@d2ed1bb
  • Loading branch information
sylwiaszunejko authored and dkropachev committed Jun 14, 2024
1 parent 624fc1d commit 67b02d5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions udt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 67b02d5

Please sign in to comment.