diff --git a/bundle/tests/variables/empty/databricks.yml b/bundle/tests/variables/empty/databricks.yml new file mode 100644 index 0000000000..f90f6211c4 --- /dev/null +++ b/bundle/tests/variables/empty/databricks.yml @@ -0,0 +1,7 @@ +variables: + a: + description: empty variable + default: + +bundle: + name: empty${var.a} diff --git a/bundle/tests/variables_test.go b/bundle/tests/variables_test.go index 7cf0f72f03..51a23e5d5d 100644 --- a/bundle/tests/variables_test.go +++ b/bundle/tests/variables_test.go @@ -193,3 +193,9 @@ func TestVariableTargetOverrides(t *testing.T) { }) } } + +func TestBundleWithEmptyVariableLoads(t *testing.T) { + b := load(t, "./variables/empty") + diags := bundle.Apply(context.Background(), b, mutator.SetVariables()) + require.ErrorContains(t, diags.Error(), "no value assigned to required variable a") +} diff --git a/libs/dyn/convert/to_typed.go b/libs/dyn/convert/to_typed.go index 8febe87aee..181c88cc97 100644 --- a/libs/dyn/convert/to_typed.go +++ b/libs/dyn/convert/to_typed.go @@ -282,6 +282,11 @@ func toTypedFloat(dst reflect.Value, src dyn.Value) error { } func toTypedInterface(dst reflect.Value, src dyn.Value) error { + if src.Kind() == dyn.KindNil { + dst.Set(reflect.Zero(dst.Type())) + return nil + } + dst.Set(reflect.ValueOf(src.AsAny())) return nil } diff --git a/libs/dyn/convert/to_typed_test.go b/libs/dyn/convert/to_typed_test.go index 5e37f28631..37d85539c8 100644 --- a/libs/dyn/convert/to_typed_test.go +++ b/libs/dyn/convert/to_typed_test.go @@ -533,3 +533,10 @@ func TestToTypedAnyWithMap(t *testing.T) { require.NoError(t, err) assert.Equal(t, map[string]any{"foo": "bar", "bar": "baz"}, out) } + +func TestToTypedAnyWithNil(t *testing.T) { + var out any + err := ToTyped(&out, dyn.NilValue) + require.NoError(t, err) + assert.Equal(t, nil, out) +}