Skip to content

Commit

Permalink
Added another check that object parameter type is the same as value t…
Browse files Browse the repository at this point in the history
…ype in hasAttrib

Signed-off-by: Theodor Mihalache <[email protected]>
  • Loading branch information
tmihalac committed Nov 25, 2024
1 parent aea02e6 commit 1891c08
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion infra/feast-operator/internal/controller/services/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,17 @@ func hasAttrib(s interface{}, fieldName string, value interface{}) (bool, error)
return false, fmt.Errorf("cannot set field %s", fieldName)
}

// Ensure the field type matches the value type
valType := reflect.ValueOf(value)

if field.Kind() != valType.Kind() {
return false, fmt.Errorf("type mismatch: field type %v and value type %v do not match", field.Kind(), valType.Kind())
}

// Check if the field is empty (zero value)
if field.IsZero() {
// Set the field value only if it's empty
field.Set(reflect.ValueOf(value))
field.Set(reflect.ValueOf(valType))
}

return true, nil
Expand Down

0 comments on commit 1891c08

Please sign in to comment.