Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/bundles/required-skip-reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Removed spurious "required field is not set" warnings for a field whose value is a reference to a whole block, such as `schedule: ${resources.jobs.base.schedule}`. ([#7226](https://github.com/databricks/cli/pull/7226))
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@

>>> [CLI] bundle validate
Warning: required field "quartz_cron_expression" is not set
at resources.jobs.viaref.schedule
in databricks.yml:9:17

Warning: required field "timezone_id" is not set
at resources.jobs.viaref.schedule
in databricks.yml:9:17

Name: test-bundle
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default

Found 2 warnings
Validation OK!

>>> [CLI] bundle plan -o json
Warning: required field "quartz_cron_expression" is not set
at resources.jobs.viaref.schedule
in databricks.yml:9:17

Warning: required field "timezone_id" is not set
at resources.jobs.viaref.schedule
in databricks.yml:9:17

{
"pause_status": "UNPAUSED",
"quartz_cron_expression": "0 0 * * * ?",
Expand Down

This file was deleted.

7 changes: 7 additions & 0 deletions bundle/config/validate/required.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/databricks/cli/bundle/internal/validation/generated"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/dyn/dynvar"
"github.com/databricks/cli/libs/structs/structpath"
)

Expand Down Expand Up @@ -50,6 +51,12 @@ func warnForMissingFields(ctx context.Context, b *bundle.Bundle) diag.Diagnostic
return nil
}

// A pure reference (e.g. "${resources.jobs.base.schedule}") has no fields of its own;
// the referenced value is checked where it is defined.
if s, ok := v.AsString(); ok && dynvar.IsPureVariableReference(s) {
return nil
}

fields := generated.RequiredFields[pattern.String()]
for _, field := range fields {
vv := v.Get(field)
Expand Down
29 changes: 29 additions & 0 deletions bundle/config/validate/required_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package validate

import (
"testing"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestRequiredSkipsPureReference(t *testing.T) {
root, diags := config.LoadFromBytes("databricks.yml", []byte(`
resources:
jobs:
viaref:
schedule: ${resources.jobs.base.schedule}
missing:
schedule:
timezone_id: UTC
`))
require.Empty(t, diags)
b := &bundle.Bundle{Config: *root}

diags = Required().Apply(t.Context(), b)
require.Len(t, diags, 1)
assert.Equal(t, `required field "quartz_cron_expression" is not set`, diags[0].Summary)
assert.Equal(t, "resources.jobs.missing.schedule", diags[0].Paths[0].String())
}
Loading