diff --git a/.nextchanges/bundles/8166.md b/.nextchanges/bundles/8166.md new file mode 100644 index 00000000000..edcefdd7372 --- /dev/null +++ b/.nextchanges/bundles/8166.md @@ -0,0 +1 @@ +* Fix target overrides of `mode`, `cluster_id` and `git` failing with `expected a map to index ..., found nil` when the top-level `bundle` key is empty. ([#8166](https://github.com/databricks/cli/pull/8166)) diff --git a/acceptance/bundle/override/null-bundle-key/output.txt b/acceptance/bundle/override/null-bundle-key/output.txt index c7c506a0e1f..6079869b9b3 100644 --- a/acceptance/bundle/override/null-bundle-key/output.txt +++ b/acceptance/bundle/override/null-bundle-key/output.txt @@ -1,21 +1,24 @@ >>> errcode [CLI] bundle validate -o json -t with_mode -Error: failed to perform target override for target=with_mode: expected a map to index "bundle.mode", found nil - +Warning: required field "name" is not set + at bundle + in databricks.yml:3:8 -Exit code: 1 +json.bundle.mode = "development"; >>> errcode [CLI] bundle validate -o json -t with_cluster_id -Error: failed to perform target override for target=with_cluster_id: expected a map to index "bundle.cluster_id", found nil - +Warning: required field "name" is not set + at bundle + in databricks.yml:3:8 -Exit code: 1 +json.bundle.cluster_id = "0123-456789-abcdef"; >>> errcode [CLI] bundle validate -o json -t with_git -Error: failed to perform target override for target=with_git: expected a map to index "bundle.git", found nil - +Warning: required field "name" is not set + at bundle + in databricks.yml:3:8 -Exit code: 1 +json.bundle.git.branch = "main"; >>> errcode [CLI] bundle validate -o json -t without_overrides Warning: required field "name" is not set diff --git a/acceptance/bundle/override/null-bundle-key/test.toml b/acceptance/bundle/override/null-bundle-key/test.toml deleted file mode 100644 index 192283e1500..00000000000 --- a/acceptance/bundle/override/null-bundle-key/test.toml +++ /dev/null @@ -1 +0,0 @@ -Badness = "When the bundle key is null, a target that sets mode, cluster_id or git fails with 'expected a map to index \"bundle.mode\", found nil'. It should apply the override, as it does when the bundle key is an empty map." diff --git a/bundle/config/root.go b/bundle/config/root.go index 637d38d3b9f..62f1232df0e 100644 --- a/bundle/config/root.go +++ b/bundle/config/root.go @@ -402,9 +402,10 @@ func (r *Root) MergeTargetOverrides(name string) error { } } - // Below, we're setting fields on the bundle key, so make sure it exists. - if root.Get("bundle").Kind() == dyn.KindInvalid { - root, err = dyn.Set(root, "bundle", dyn.V(map[string]dyn.Value{})) + // Below, we're setting fields on the bundle key, so make sure it is a map. + // It is null when the key is present but empty, e.g. all its fields are commented out. + if b := root.Get("bundle"); b.Kind() == dyn.KindInvalid || b.Kind() == dyn.KindNil { + root, err = dyn.Set(root, "bundle", dyn.NewValue(map[string]dyn.Value{}, b.Locations())) if err != nil { return err }