Skip to content

Reject references to missing resource fields in bundle validate, before deploy uploads files - #8070

Draft
denik wants to merge 4 commits into
mainfrom
denik/validate-reference-fields
Draft

denik wants to merge 4 commits into
mainfrom
denik/validate-reference-fields

Conversation

@denik

@denik denik commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Changes

bundle validate now rejects a reference to a field that the target resource type does not have, such as ${resources.volumes.bar.non_existent}. bundle plan and bundle deploy reject it before they upload anything or call the workspace. All three report the same error at the reference's location:

Error: cannot resolve "${resources.volumes.bar.non_existent}": resource type "volumes" has no field "non_existent"
  at resources.volumes.foo.catalog_name
  in databricks.yml:11:21

How it works:

  • The check reuses the planner's own rule from LookupReferencePreDeploy. A field must exist in the target's state type or its remote type, after Terraform-to-DABs path translation, and id always exists. That rule is now one function, checkReferenceFieldExists, which the planner and the new check share.
  • It visits only the references the planner resolves. extractReferences is refactored into walkReferences, which both use.
  • It visits only the nodes the planner plans. A new empty node is skipped, as makePlan skips it. A node with state is always visited.
  • Targets the planner reports with another error are left to it: missing resources, Terraform-only fields, unparsable references.
  • It runs in two places. In validate.Validate (only bundle validate runs this). And as the first step of phases.PreDeployChecks, which runs after the build for plan, deploy, pipelines deploy and apps deploy. The after-build run sees exactly the config the planner sees.
  • The python wheel wrapper moves wheel task parameters and wheel libraries out of the job during the build. With the wrapper on, bundle validate skips those two fields. The after-build check has no such skip.
  • The planner's error for the same case now uses the same message instead of naming Go types.

Why

The Badness note on acceptance/bundle/resource_deps/non_existent_field:

validate accepts ${resources.volumes.bar.non_existent}, and deploy uploads the files before planning fails. The error names internal types ('field "non_existent" not found in dresources.VolumeState; ... catalog.VolumeInfo'); validate should reject it with a user-facing message that volumes have no such field.

Before, bundle validate passed and bundle deploy printed:

Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
Error: cannot plan resources.volumes.foo: cannot resolve "${resources.volumes.bar.non_existent}": schema mismatch: non_existent: field "non_existent" not found in dresources.VolumeState; non_existent: field "non_existent" not found in catalog.VolumeInfo

Error: planning failed

After, validate, plan and deploy all fail with the error above, and deploy uploads nothing.

This only turns an existing failure into an earlier and clearer one. The check rejects only references that the planner rejects on every deploy. References to fields that exist only remotely or are filled in by the server keep passing, such as apps.*.url, pipelines.*.state and pipelines.*.creator_user_name. So do map keys, id, Terraform-style paths, and permissions or grants entries.

Dashboard: TestAccept/bundle/resource_deps/non_existent_field (the Badness note; no CI failures).

Tests

  • acceptance/bundle/resource_deps/non_existent_field: validate, plan and deploy each show the new error. Deploy shows no upload. The Badness note is removed.

  • New acceptance/bundle/resource_deps/non_existent_field_wheel_wrapper: a bad reference in wrapped wheel task parameters still passes validate, plan and deploy, as today. A bad reference elsewhere in the same job is rejected by validate and deploy. Mutation check: without the wheel skip, the test fails.

  • acceptance/bundle/variables/resolve-resources-fields references schemas.bar.non_existing and only runs validate. Deploy has always rejected that reference, and validate now reports it. The script prints the JSON as before. This is the same script shape as #7989, which also touches this test.

  • Unit tests (bundle/direct/reference_fields_test.go) cover:

    • fields that resolve and must keep passing: state, remote-only, id, map keys, Terraform-style paths, permissions and grants entries;
    • references that are skipped: Terraform-only fields, input-only fields such as volume_path, non-resource references, dotted resource keys, missing target resources, a whole-node reference in a new empty node;
    • an empty node with state, which is checked.

    Mutation checks: dropping the remote-type half of the rule, the empty-node skip or the missing-target skip each fails a case.

  • TestLookupReferencePreDeploy_UnknownField pins that the planner and the check return the same error.

  • The whole TestAccept/bundle suite passes locally. bundle/deploy/mlops-stacks fails the same way on main in this environment.

Gaps and risks

  • bundle validate runs before the build, so it can still report a false error in one case. A local library path with a reference in its directory part, where a directory with that literal name exists, is rewritten by the build, and the plan never sees the reference. Plan and deploy are exact because their check runs after the build.
  • Missed rejects, all of which behave as they do today (the plan rejects them later):
    • references the planner adds itself (PrepareInputConfig);
    • immutable-mode snapshot permissions (internal_immutable_snapshots, registered after PreDeployChecks);
    • with the wheel wrapper on, wheel tasks that the wrapper leaves alone, at validate only.
  • Judgment call: running the plan before the file upload would cover every plan error with one mechanism. That is a larger change to the deploy order, so this PR adds the targeted check instead. The check costs one in-memory pass per validate, plan or deploy (InitAll(nil), about 1-10 ms, plus per-resource state preparation).
  • Overlap with #7989, which detects cycles in validate with the same approach. Both add a mutator in bundle/config/validate and touch resolve-resources-fields. Whichever merges second needs a small rebase.
  • Risk: medium. This is a new rejection on the validate, plan and deploy paths, designed to reject only what the planner already rejects.

This PR fixes behavior recorded as Badness in acceptance tests.

AI agent (opus5.5, isaac_claude)

🤖 This pull request and its description were written by Isaac.

denik and others added 3 commits November 26, 2026 15:53
…oy uploads files

bundle validate accepted ${resources.volumes.bar.non_existent}; plan and deploy
failed only at planning, after deploy had uploaded the bundle files, with an
error naming internal Go types. Validate and the pre-deploy checks now apply
the planner's own check (the field must exist in the state or the remote
type of the target resource) and report a user-facing error at the
reference's location. The plan reports the same message.

Co-authored-by: Isaac <no-reply@databricks.com>
…ow the wheel wrapper skip, share the planner check

Co-authored-by: Isaac <no-reply@databricks.com>
…raries, name the field as written

Co-authored-by: Isaac <no-reply@databricks.com>
@github-actions github-actions Bot added the DABs DABs related issues label Nov 26, 2026
Co-authored-by: Isaac <no-reply@databricks.com>
@github-actions

Copy link
Copy Markdown
Contributor

Regression test report ✅

Commit: aa75a0f7d | Workflow run

Selected 3 changed tests (limit=20, 0 not selected)

6 tests: regression=6 unreleased=0 coverage=0 failing=0
test branch main (7a48abb) latest (v1.28.0)
TestAccept/bundle/resource_deps/non_existent_field/DMS= ✅ ❌ ❌
TestAccept/bundle/resource_deps/non_existent_field/DMS=true ✅ ❌ ❌
TestAccept/bundle/resource_deps/non_existent_field_wheel_wrapper/DMS= ✅ ❌ ❌
TestAccept/bundle/resource_deps/non_existent_field_wheel_wrapper/DMS=true ✅ ❌ ❌
TestAccept/bundle/variables/resolve-resources-fields/DMS= ✅ ❌ ❌
TestAccept/bundle/variables/resolve-resources-fields/DMS=true ✅ ❌ ❌
TestAccept/bundle/resource_deps/non_existent_field/DMS=: branch ✅ | main (7a48abb) ❌ | latest (v1.28.0) ❌

main (7a48abb):

acceptance_test.go:1402: 
        	Error Trace:	/home/runner/work/cli/cli/libs/testdiff/testdiff.go:22
        	            				/home/runner/work/cli/cli/acceptance/acceptance_test.go:1402
        	            				/home/runner/work/cli/cli/acceptance/acceptance_test.go:1143
        	            				/home/runner/work/cli/cli/acceptance/acceptance_test.go:704
        	Error:      	Not equal: 
        	            	expected: "\n>>> musterr [CLI] bundle validate\nError: cannot resolve \"${resources.volumes.bar.non_existent}\": resource type \"volumes\" has no field \"non_existent\"\n  at resources.volumes.foo.catalog_name\n  in databricks.yml:11:21\n\nName: test-bundle\nTarget: default\nWorkspace:\n  User: [USERNAME]\n  Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default\n\nFound 1 error\n\n>>> musterr [CLI] bundle plan\nError: cannot resolve \"${resources.volumes.bar.non_existent}\": resource type \"volumes\" has no field \"non_existent\"\n  at resources.volumes.foo.catalog_name\n  in databricks.yml:11:21\n\n\n>>> musterr [CLI] bundle deploy\nError: cannot resolve \"${resources.volumes.bar.non_existent}\": resource type \"volumes\" has no field \"non_existent\"\n  at resources.volumes.foo.catalog_name\n  in databricks.yml:11:21\n\n"
        	            	actual  : "\n>>> musterr [CLI] bundle validate\nName: test-bundle\nTarget: default\nWorkspace:\n  User: [USERNAME]\n  Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default\n\nValidation OK!\n\nUnexpected success\n\nExit code: 1\n"
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -2,6 +2,2 @@
        	            	 >>> musterr [CLI] bundle validate
        	            	-Error: cannot resolve "${resources.volumes.bar.non_existent}": resource type "volumes" has no field "non_existent"
        	            	-  at resources.volumes.foo.catalog_name
        	            	-  in databricks.yml:11:21
        	            	-
        	            	 Name: test-bundle
        	            	@@ -12,15 +8,7 @@
        	            	 
        	            	-Found 1 error
        	            	+Validation OK!
        	            	 
        	            	->>> musterr [CLI] bundle plan
        	            	-Error: cannot resolve "${resources.volumes.bar.non_existent}": resource type "volumes" has no field "non_existent"
        	            	-  at resources.volumes.foo.catalog_name
        	            	-  in databricks.yml:11:21
        	            	+Unexpected success
        	            	 
        	            	+Exit code: 1
        	            	 
        	            	->>> musterr [CLI] bundle deploy
        	            	-Error: cannot resolve "${resources.volumes.bar.non_existent}": resource type "volumes" has no field "non_existent"
        	            	-  at resources.volumes.foo.catalog_name
        	            	-  in databricks.yml:11:21
        	            	-
        	            	-
        	Test:       	TestAccept/bundle/resource_deps/non_existent_field/DMS=
        	Messages:   	bundle/resource_deps/non_existent_field/output.txt vs /tmp/TestAcceptbundleresource_depsnon_existent_fieldDMS=3102084197/002/output.txt

latest (v1.28.0): same output as main (7a48abb)

TestAccept/bundle/resource_deps/non_existent_field/DMS=true: branch ✅ | main (7a48abb) ❌ | latest (v1.28.0) ❌

main (7a48abb):

acceptance_test.go:1402: 
        	Error Trace:	/home/runner/work/cli/cli/libs/testdiff/testdiff.go:22
        	            				/home/runner/work/cli/cli/acceptance/acceptance_test.go:1402
        	            				/home/runner/work/cli/cli/acceptance/acceptance_test.go:1143
        	            				/home/runner/work/cli/cli/acceptance/acceptance_test.go:704
        	Error:      	Not equal: 
        	            	expected: "\n>>> musterr [CLI] bundle validate\nError: cannot resolve \"${resources.volumes.bar.non_existent}\": resource type \"volumes\" has no field \"non_existent\"\n  at resources.volumes.foo.catalog_name\n  in databricks.yml:11:21\n\nName: test-bundle\nTarget: default\nWorkspace:\n  User: [USERNAME]\n  Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default\n\nFound 1 error\n\n>>> musterr [CLI] bundle plan\nError: cannot resolve \"${resources.volumes.bar.non_existent}\": resource type \"volumes\" has no field \"non_existent\"\n  at resources.volumes.foo.catalog_name\n  in databricks.yml:11:21\n\n\n>>> musterr [CLI] bundle deploy\nError: cannot resolve \"${resources.volumes.bar.non_existent}\": resource type \"volumes\" has no field \"non_existent\"\n  at resources.volumes.foo.catalog_name\n  in databricks.yml:11:21\n\n"
        	            	actual  : "\n>>> musterr [CLI] bundle validate\nName: test-bundle\nTarget: default\nWorkspace:\n  User: [USERNAME]\n  Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default\n\nValidation OK!\n\nUnexpected success\n\nExit code: 1\n"
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -2,6 +2,2 @@
        	            	 >>> musterr [CLI] bundle validate
        	            	-Error: cannot resolve "${resources.volumes.bar.non_existent}": resource type "volumes" has no field "non_existent"
        	            	-  at resources.volumes.foo.catalog_name
        	            	-  in databricks.yml:11:21
        	            	-
        	            	 Name: test-bundle
        	            	@@ -12,15 +8,7 @@
        	            	 
        	            	-Found 1 error
        	            	+Validation OK!
        	            	 
        	            	->>> musterr [CLI] bundle plan
        	            	-Error: cannot resolve "${resources.volumes.bar.non_existent}": resource type "volumes" has no field "non_existent"
        	            	-  at resources.volumes.foo.catalog_name
        	            	-  in databricks.yml:11:21
        	            	+Unexpected success
        	            	 
        	            	+Exit code: 1
        	            	 
        	            	->>> musterr [CLI] bundle deploy
        	            	-Error: cannot resolve "${resources.volumes.bar.non_existent}": resource type "volumes" has no field "non_existent"
        	            	-  at resources.volumes.foo.catalog_name
        	            	-  in databricks.yml:11:21
        	            	-
        	            	-
        	Test:       	TestAccept/bundle/resource_deps/non_existent_field/DMS=true
        	Messages:   	bundle/resource_deps/non_existent_field/output.txt vs /tmp/TestAcceptbundleresource_depsnon_existent_fieldDMS=true2517165002/002/output.txt

latest (v1.28.0):

acceptance_test.go:1402: 
        	Error Trace:	/home/runner/work/cli/cli/libs/testdiff/testdiff.go:22
        	            				/home/runner/work/cli/cli/acceptance/acceptance_test.go:1402
        	            				/home/runner/work/cli/cli/acceptance/acceptance_test.go:1143
        	            				/home/runner/work/cli/cli/acceptance/acceptance_test.go:704
        	Error:      	Not equal: 
        	            	expected: "\n>>> musterr [CLI] bundle validate\nError: cannot resolve \"${resources.volumes.bar.non_existent}\": resource type \"volumes\" has no field \"non_existent\"\n  at resources.volumes.foo.catalog_name\n  in databricks.yml:11:21\n\nName: test-bundle\nTarget: default\nWorkspace:\n  User: [USERNAME]\n  Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default\n\nFound 1 error\n\n>>> musterr [CLI] bundle plan\nError: cannot resolve \"${resources.volumes.bar.non_existent}\": resource type \"volumes\" has no field \"non_existent\"\n  at resources.volumes.foo.catalog_name\n  in databricks.yml:11:21\n\n\n>>> musterr [CLI] bundle deploy\nError: cannot resolve \"${resources.volumes.bar.non_existent}\": resource type \"volumes\" has no field \"non_existent\"\n  at resources.volumes.foo.catalog_name\n  in databricks.yml:11:21\n\n"
        	            	actual  : "\n>>> musterr [CLI] bundle validate\nName: test-bundle\nTarget: default\nWorkspace:\n  User: [USERNAME]\n  Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default\n\nValidation OK!\n\nUnexpected success\n\nExit code: 1\n"
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -2,6 +2,2 @@
        	            	 >>> musterr [CLI] bundle validate
        	            	-Error: cannot resolve "${resources.volumes.bar.non_existent}": resource type "volumes" has no field "non_existent"
        	            	-  at resources.volumes.foo.catalog_name
        	            	-  in databricks.yml:11:21
        	            	-
        	            	 Name: test-bundle
        	            	@@ -12,15 +8,7 @@
        	            	 
        	            	-Found 1 error
        	            	+Validation OK!
        	            	 
        	            	->>> musterr [CLI] bundle plan
        	            	-Error: cannot resolve "${resources.volumes.bar.non_existent}": resource type "volumes" has no field "non_existent"
        	            	-  at resources.volumes.foo.catalog_name
        	            	-  in databricks.yml:11:21
        	            	+Unexpected success
        	            	 
        	            	+Exit code: 1
        	            	 
        	            	->>> musterr [CLI] bundle deploy
        	            	-Error: cannot resolve "${resources.volumes.bar.non_existent}": resource type "volumes" has no field "non_existent"
        	            	-  at resources.volumes.foo.catalog_name
        	            	-  in databricks.yml:11:21
        	            	-
        	            	-
        	Test:       	TestAccept/bundle/resource_deps/non_existent_field/DMS=true
        	Messages:   	bundle/resource_deps/non_existent_field/output.txt vs /tmp/TestAcceptbundleresource_depsnon_existent_fieldDMS=true3467875363/002/output.txt
FAIL
TestAccept/bundle/resource_deps/non_existent_field_wheel_wrapper/DMS=: branch ✅ | main (7a48abb) ❌ | latest (v1.28.0) ❌

main (7a48abb):

acceptance_test.go:1402: Diff:
        --- bundle/resource_deps/non_existent_field_wheel_wrapper/output.txt
        +++ /tmp/TestAcceptbundleresource_depsnon_existent_field_wheel_wrapper2578141130/002/output.txt
        @@ -22,20 +22,14 @@
         === The wrapper does not move a reference outside the wheel task
         
         >>> musterr [CLI] bundle validate
        -Error: cannot resolve "${resources.jobs.whl.non_existent}": resource type "jobs" has no field "non_existent"
        -  at resources.jobs.whl.name
        -  in databricks.yml:10:13
        -
         Name: test-bundle
         Target: default
         Workspace:
           User: [USERNAME]
           Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
         
        -Found 1 error
        +Validation OK!
         
        ->>> musterr [CLI] bundle deploy
        -Error: cannot resolve "${resources.jobs.whl.non_existent}": resource type "jobs" has no field "non_existent"
        -  at resources.jobs.whl.name
        -  in databricks.yml:10:13
        +Unexpected success
         
        +Exit code: 1

latest (v1.28.0): same output as main (7a48abb)

TestAccept/bundle/resource_deps/non_existent_field_wheel_wrapper/DMS=true: branch ✅ | main (7a48abb) ❌ | latest (v1.28.0) ❌

main (7a48abb):

acceptance_test.go:1402: Diff:
        --- bundle/resource_deps/non_existent_field_wheel_wrapper/output.txt
        +++ /tmp/TestAcceptbundleresource_depsnon_existent_field_wheel_wrapper4106972126/002/output.txt
        @@ -22,20 +22,14 @@
         === The wrapper does not move a reference outside the wheel task
         
         >>> musterr [CLI] bundle validate
        -Error: cannot resolve "${resources.jobs.whl.non_existent}": resource type "jobs" has no field "non_existent"
        -  at resources.jobs.whl.name
        -  in databricks.yml:10:13
        -
         Name: test-bundle
         Target: default
         Workspace:
           User: [USERNAME]
           Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
         
        -Found 1 error
        +Validation OK!
         
        ->>> musterr [CLI] bundle deploy
        -Error: cannot resolve "${resources.jobs.whl.non_existent}": resource type "jobs" has no field "non_existent"
        -  at resources.jobs.whl.name
        -  in databricks.yml:10:13
        +Unexpected success
         
        +Exit code: 1
        
FAIL

latest (v1.28.0):

acceptance_test.go:1402: Diff:
        --- bundle/resource_deps/non_existent_field_wheel_wrapper/output.txt
        +++ /tmp/TestAcceptbundleresource_depsnon_existent_field_wheel_wrapper2246608000/002/output.txt
        @@ -22,20 +22,14 @@
         === The wrapper does not move a reference outside the wheel task
         
         >>> musterr [CLI] bundle validate
        -Error: cannot resolve "${resources.jobs.whl.non_existent}": resource type "jobs" has no field "non_existent"
        -  at resources.jobs.whl.name
        -  in databricks.yml:10:13
        -
         Name: test-bundle
         Target: default
         Workspace:
           User: [USERNAME]
           Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
         
        -Found 1 error
        +Validation OK!
         
        ->>> musterr [CLI] bundle deploy
        -Error: cannot resolve "${resources.jobs.whl.non_existent}": resource type "jobs" has no field "non_existent"
        -  at resources.jobs.whl.name
        -  in databricks.yml:10:13
        +Unexpected success
         
        +Exit code: 1
TestAccept/bundle/variables/resolve-resources-fields/DMS=: branch ✅ | main (7a48abb) ❌ | latest (v1.28.0) ❌

main (7a48abb):

acceptance_test.go:1402: Diff:
        --- bundle/variables/resolve-resources-fields/output.txt
        +++ /tmp/TestAcceptbundlevariablesresolve-resources-fieldsDMS=1160505754/002/output.txt
        @@ -1,9 +1,3 @@
        -Error: cannot resolve "${resources.schemas.bar.non_existing}": resource type "schemas" has no field "non_existing"
        -  at resources.schemas.foo.comment
        -  in databricks.yml:16:16
        -
        -
        -Exit code: 1
         {
           "a": {
             "default": "${resources.schemas.foo.name}",

latest (v1.28.0): same output as main (7a48abb)

TestAccept/bundle/variables/resolve-resources-fields/DMS=true: branch ✅ | main (7a48abb) ❌ | latest (v1.28.0) ❌

main (7a48abb):

acceptance_test.go:1402: Diff:
        --- bundle/variables/resolve-resources-fields/output.txt
        +++ /tmp/TestAcceptbundlevariablesresolve-resources-fieldsDMS=true3869489058/002/output.txt
        @@ -1,9 +1,3 @@
        -Error: cannot resolve "${resources.schemas.bar.non_existing}": resource type "schemas" has no field "non_existing"
        -  at resources.schemas.foo.comment
        -  in databricks.yml:16:16
        -
        -
        -Exit code: 1
         {
           "a": {
             "default": "${resources.schemas.foo.name}",

latest (v1.28.0): same output as main (7a48abb)

@eng-dev-ecosystem-bot

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: aa75a0f

Run: 45863379686

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 279 22 4:13
💚​ aws-windows-latest-4core-16gb 1 281 20 3:28
💚​ azure linux-2core-8gb 1 278 22 3:48
💚​ azure-windows-latest-4core-16gb 1 280 20 3:44
💚​ gcp linux-2core-8gb 1 279 22 4:38
💚​ gcp-windows-latest-4core-16gb 1 281 20 3:32
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 4 slowest tests (at least 2 minutes):
duration env testname
3:41 azure-windows-latest-4core-16gb TestAccept
3:30 gcp-windows-latest-4core-16gb TestAccept
3:27 aws-windows-latest-4core-16gb TestAccept
2:02 aws linux-2core-8gb TestAccept

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DABs DABs related issues factory-generated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants