diff --git a/bundle/deploy/terraform/convert_test.go b/bundle/deploy/terraform/convert_test.go index f6369630c5..7ea4485388 100644 --- a/bundle/deploy/terraform/convert_test.go +++ b/bundle/deploy/terraform/convert_test.go @@ -459,6 +459,10 @@ func TestBundleToTerraformModelServingPermissions(t *testing.T) { // Need to specify this to satisfy the equivalence test: // The previous method of generation includes the "create" field // because it is required (not marked as `omitempty`). + // The previous method used [json.Marshal] from the standard library + // and as such observed the `omitempty` tag. + // The new method leverages [dyn.Value] where any field that is not + // explicitly set is not part of the value. Config: serving.EndpointCoreConfigInput{ ServedModels: []serving.ServedModelInput{ { diff --git a/libs/dyn/convert/from_typed.go b/libs/dyn/convert/from_typed.go index d0be327a2f..af49a07abe 100644 --- a/libs/dyn/convert/from_typed.go +++ b/libs/dyn/convert/from_typed.go @@ -25,6 +25,11 @@ const ( // FromTyped converts changes made in the typed structure w.r.t. the configuration value // back to the configuration value, retaining existing location information where possible. +// +// It uses the reference value both for location information and to determine if the typed +// value was changed or not. For example, if a struct-by-value field is nil in the reference +// it will be zero-valued in the typed configuration. If it remains zero-valued, this +// this function will still emit a nil value in the dynamic representation. func FromTyped(src any, ref dyn.Value) (dyn.Value, error) { return fromTyped(src, ref) } @@ -110,7 +115,7 @@ func fromTypedStruct(src reflect.Value, ref dyn.Value, options ...fromTypedOptio // Return the new mapping if: // 1. The mapping has entries (i.e. the struct was not empty). // 2. The reference is a map (i.e. the struct was and still is empty). - // 3. The "includeZeroValuedScalars" option is set (i.e. the struct is a non-nil pointer). + // 3. The "includeZeroValues" option is set (i.e. the struct is a non-nil pointer). if out.Len() > 0 || ref.Kind() == dyn.KindMap || slices.Contains(options, includeZeroValues) { return dyn.NewValue(out, ref.Location()), nil }