Skip to content

Commit aacff9c

Browse files
denikIsaac
andauthored
Report target compute_id deprecation at targets.<name>.compute_id (#7048)
## Changes The `compute_id is deprecated` warning for a target-level `compute_id` now says `at targets.<name>.compute_id` instead of `at compute_id`. ## Tests `acceptance/bundle/validate/compute_id_location` (from #7029) records the corrected path. Stacked on #7029. This pull request and its description were written by Isaac. --------- Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 71934db commit aacff9c

4 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎.nextchanges/bundles/7048.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* The `compute_id` deprecation warning for a target now shows the full path (`targets.<name>.compute_id`). ([#7048](https://github.com/databricks/cli/pull/7048))

‎acceptance/bundle/validate/compute_id_location/output.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Warning: compute_id is deprecated, please use cluster_id instead
66
in databricks.yml:3:15
77

88
Warning: compute_id is deprecated, please use cluster_id instead
9-
at compute_id
9+
at targets.dev.compute_id
1010
in databricks.yml:7:17
1111

1212
Name: test-bundle
@@ -24,7 +24,7 @@ Warning: compute_id is deprecated, please use cluster_id instead
2424
in databricks.yml:3:15
2525

2626
Warning: compute_id is deprecated, please use cluster_id instead
27-
at compute_id
27+
at targets.dev.compute_id
2828
in databricks.yml:7:17
2929

3030
Name: test-bundle
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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."
1+
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."

‎bundle/config/mutator/compute_id_compat.go‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package mutator
22

33
import (
44
"context"
5+
"slices"
56

67
"github.com/databricks/cli/bundle"
78
"github.com/databricks/cli/libs/diag"
@@ -23,12 +24,12 @@ func (m *computeIdToClusterId) Apply(ctx context.Context, b *bundle.Bundle) diag
2324

2425
// The "compute_id" key is set; rewrite it to "cluster_id".
2526
err := b.Config.Mutate(func(v dyn.Value) (dyn.Value, error) {
26-
v, d := rewriteComputeIdToClusterId(v, dyn.NewPath(dyn.Key("bundle")))
27+
v, d := rewriteComputeIdToClusterId(v, dyn.NewPath(dyn.Key("bundle")), nil)
2728
diags = diags.Extend(d)
2829

2930
// Check if the "compute_id" key is set in any target overrides.
3031
return dyn.MapByPattern(v, dyn.NewPattern(dyn.Key("targets"), dyn.AnyKey()), func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
31-
v, d := rewriteComputeIdToClusterId(v, dyn.Path{})
32+
v, d := rewriteComputeIdToClusterId(v, dyn.Path{}, p)
3233
diags = diags.Extend(d)
3334
return v, nil
3435
})
@@ -38,7 +39,9 @@ func (m *computeIdToClusterId) Apply(ctx context.Context, b *bundle.Bundle) diag
3839
return diags
3940
}
4041

41-
func rewriteComputeIdToClusterId(v dyn.Value, p dyn.Path) (dyn.Value, diag.Diagnostics) {
42+
// rewriteComputeIdToClusterId rewrites p.compute_id to p.cluster_id in v; prefix is the
43+
// path of v in the configuration, used in the diagnostic.
44+
func rewriteComputeIdToClusterId(v dyn.Value, p, prefix dyn.Path) (dyn.Value, diag.Diagnostics) {
4245
var diags diag.Diagnostics
4346
computeIdPath := p.Append(dyn.Key("compute_id"))
4447
computeId, err := dyn.GetByPath(v, computeIdPath)
@@ -55,7 +58,7 @@ func rewriteComputeIdToClusterId(v dyn.Value, p dyn.Path) (dyn.Value, diag.Diagn
5558
Severity: diag.Warning,
5659
Summary: "compute_id is deprecated, please use cluster_id instead",
5760
Locations: computeId.Locations(),
58-
Paths: dyn.ToStructPaths(computeIdPath),
61+
Paths: dyn.ToStructPaths(slices.Concat(prefix, computeIdPath)),
5962
})
6063

6164
clusterIdPath := p.Append(dyn.Key("cluster_id"))

0 commit comments

Comments
 (0)