From bbee4655bf4cf873ef6798abc8d47c92292d9915 Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Sat, 28 Nov 2026 08:35:14 +0000 Subject: [PATCH] Fix target overrides when the bundle key is null An empty bundle key in databricks.yml is a null value, not a missing one, so the guard that creates the bundle map before setting mode, cluster_id and git did not fire and SetByPath failed with 'expected a map to index "bundle.mode", found nil'. Treat null like missing and keep its location. Co-authored-by: Isaac --- .nextchanges/bundles/8166.md | 1 + .../override/null-bundle-key/output.txt | 21 +++++++++++-------- .../bundle/override/null-bundle-key/test.toml | 1 - bundle/config/root.go | 7 ++++--- 4 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 .nextchanges/bundles/8166.md delete mode 100644 acceptance/bundle/override/null-bundle-key/test.toml 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 }