From 1891c088d6975222bcbf65dd4aad90ce718d6f83 Mon Sep 17 00:00:00 2001 From: Theodor Mihalache Date: Mon, 25 Nov 2024 10:49:04 -0500 Subject: [PATCH] Added another check that object parameter type is the same as value type in hasAttrib Signed-off-by: Theodor Mihalache --- .../feast-operator/internal/controller/services/util.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/infra/feast-operator/internal/controller/services/util.go b/infra/feast-operator/internal/controller/services/util.go index 5e2daee673..a2f3ee68fa 100644 --- a/infra/feast-operator/internal/controller/services/util.go +++ b/infra/feast-operator/internal/controller/services/util.go @@ -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