diff --git a/.nextchanges/bundles/7048.md b/.nextchanges/bundles/7048.md new file mode 100644 index 00000000000..1cacffdb69c --- /dev/null +++ b/.nextchanges/bundles/7048.md @@ -0,0 +1 @@ +* The `compute_id` deprecation warning for a target now shows the full path (`targets..compute_id`). ([#7048](https://github.com/databricks/cli/pull/7048)) diff --git a/acceptance/bundle/validate/compute_id_location/output.txt b/acceptance/bundle/validate/compute_id_location/output.txt index d8d3966b1d7..559b500c30a 100644 --- a/acceptance/bundle/validate/compute_id_location/output.txt +++ b/acceptance/bundle/validate/compute_id_location/output.txt @@ -6,7 +6,7 @@ Warning: compute_id is deprecated, please use cluster_id instead in databricks.yml:3:15 Warning: compute_id is deprecated, please use cluster_id instead - at compute_id + at targets.dev.compute_id in databricks.yml:7:17 Name: test-bundle @@ -24,7 +24,7 @@ Warning: compute_id is deprecated, please use cluster_id instead in databricks.yml:3:15 Warning: compute_id is deprecated, please use cluster_id instead - at compute_id + at targets.dev.compute_id in databricks.yml:7:17 Name: test-bundle diff --git a/acceptance/bundle/validate/compute_id_location/test.toml b/acceptance/bundle/validate/compute_id_location/test.toml index d2d1c82e6d3..efba9a37db6 100644 --- a/acceptance/bundle/validate/compute_id_location/test.toml +++ b/acceptance/bundle/validate/compute_id_location/test.toml @@ -1 +1 @@ -Badness = "Target-level compute_id is reported without the target in the path (at compute_id instead of at targets.dev.compute_id), and is reported even when that target is not selected." +Badness = "A target-level compute_id is reported even when that target is not selected: the deprecation is rewritten for every target before target selection." diff --git a/bundle/config/mutator/compute_id_compat.go b/bundle/config/mutator/compute_id_compat.go index c29b01cbd1c..35568441ce8 100644 --- a/bundle/config/mutator/compute_id_compat.go +++ b/bundle/config/mutator/compute_id_compat.go @@ -2,6 +2,7 @@ package mutator import ( "context" + "slices" "github.com/databricks/cli/bundle" "github.com/databricks/cli/libs/diag" @@ -23,12 +24,12 @@ func (m *computeIdToClusterId) Apply(ctx context.Context, b *bundle.Bundle) diag // The "compute_id" key is set; rewrite it to "cluster_id". err := b.Config.Mutate(func(v dyn.Value) (dyn.Value, error) { - v, d := rewriteComputeIdToClusterId(v, dyn.NewPath(dyn.Key("bundle"))) + v, d := rewriteComputeIdToClusterId(v, dyn.NewPath(dyn.Key("bundle")), nil) diags = diags.Extend(d) // Check if the "compute_id" key is set in any target overrides. return dyn.MapByPattern(v, dyn.NewPattern(dyn.Key("targets"), dyn.AnyKey()), func(p dyn.Path, v dyn.Value) (dyn.Value, error) { - v, d := rewriteComputeIdToClusterId(v, dyn.Path{}) + v, d := rewriteComputeIdToClusterId(v, dyn.Path{}, p) diags = diags.Extend(d) return v, nil }) @@ -38,7 +39,9 @@ func (m *computeIdToClusterId) Apply(ctx context.Context, b *bundle.Bundle) diag return diags } -func rewriteComputeIdToClusterId(v dyn.Value, p dyn.Path) (dyn.Value, diag.Diagnostics) { +// rewriteComputeIdToClusterId rewrites p.compute_id to p.cluster_id in v; prefix is the +// path of v in the configuration, used in the diagnostic. +func rewriteComputeIdToClusterId(v dyn.Value, p, prefix dyn.Path) (dyn.Value, diag.Diagnostics) { var diags diag.Diagnostics computeIdPath := p.Append(dyn.Key("compute_id")) computeId, err := dyn.GetByPath(v, computeIdPath) @@ -55,7 +58,7 @@ func rewriteComputeIdToClusterId(v dyn.Value, p dyn.Path) (dyn.Value, diag.Diagn Severity: diag.Warning, Summary: "compute_id is deprecated, please use cluster_id instead", Locations: computeId.Locations(), - Paths: dyn.ToStructPaths(computeIdPath), + Paths: dyn.ToStructPaths(slices.Concat(prefix, computeIdPath)), }) clusterIdPath := p.Append(dyn.Key("cluster_id"))