From bac6ee4a8d2a3a8914bf44cfc50283b01cd818c4 Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Tue, 24 Nov 2026 15:11:13 +0000 Subject: [PATCH 1/5] direct: fail deploy and destroy when a resource delete is rejected Without deployment history, a delete rejected with an error other than not-found or permission-denied fell through to dropping the resource from state, so the command succeeded and the resource stayed in the workspace untracked. Return the error again, as before the deployment history change. Co-authored-by: Isaac --- .../bundle/destroy/delete-error/out.test.toml | 2 +- .../bundle/destroy/delete-error/output.txt | 24 ++++++++++++++++--- .../bundle/destroy/delete-error/test.toml | 4 ---- .../settled_failure/out.test.toml | 2 +- .../settled_failure/output.txt | 19 +++++++-------- .../settled_failure/script | 9 +++---- .../settled_failure/test.toml | 5 ---- bundle/direct/apply.go | 3 +-- 8 files changed, 36 insertions(+), 32 deletions(-) diff --git a/acceptance/bundle/destroy/delete-error/out.test.toml b/acceptance/bundle/destroy/delete-error/out.test.toml index 2ab253adc73..a927a5fbc06 100644 --- a/acceptance/bundle/destroy/delete-error/out.test.toml +++ b/acceptance/bundle/destroy/delete-error/out.test.toml @@ -1,2 +1,2 @@ Cloud = false -EnvMatrix.DMS = [] +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/destroy/delete-error/output.txt b/acceptance/bundle/destroy/delete-error/output.txt index dbac1f959cd..2dc2635a558 100644 --- a/acceptance/bundle/destroy/delete-error/output.txt +++ b/acceptance/bundle/destroy/delete-error/output.txt @@ -10,27 +10,45 @@ Resources: 2 created, 0 changed, 0 deleted, 0 unchanged >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/delete-error-[UNIQUE_NAME]/default/files... -Deleted jobs.bar +Error: cannot delete resources.jobs.bar: deleting id=[BAR_ID]: Fault injected by test. (400 INVALID_PARAMETER_VALUE) + +Endpoint: POST [DATABRICKS_URL]/api/2.2/jobs/delete +HTTP Status: 400 Bad Request +API error_code: INVALID_PARAMETER_VALUE +API message: Fault injected by test. + Files: 1 uploaded, 0 deleted -Resources: 0 created, 0 changed, 1 deleted, 1 unchanged + +Exit code: 1 >>> [CLI] jobs get [BAR_ID] bar-[UNIQUE_NAME] >>> print_state.py +resources.jobs.bar resources.jobs.foo === destroy: the delete of foo is rejected with 400 >>> [CLI] bundle destroy --auto-approve The following resources will be deleted: + delete resources.jobs.bar delete resources.jobs.foo All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/delete-error-[UNIQUE_NAME]/default -Destroy: 1 deleted +Error: cannot delete resources.jobs.foo: deleting id=[FOO_ID]: Fault injected by test. (400 INVALID_PARAMETER_VALUE) + +Endpoint: POST [DATABRICKS_URL]/api/2.2/jobs/delete +HTTP Status: 400 Bad Request +API error_code: INVALID_PARAMETER_VALUE +API message: Fault injected by test. + + +Exit code: 1 >>> [CLI] jobs get [FOO_ID] foo-[UNIQUE_NAME] >>> find.py \.databricks/.*resources.*\.json +.databricks/bundle/default/resources.json diff --git a/acceptance/bundle/destroy/delete-error/test.toml b/acceptance/bundle/destroy/delete-error/test.toml index 5295644db26..0b34135a1cd 100644 --- a/acceptance/bundle/destroy/delete-error/test.toml +++ b/acceptance/bundle/destroy/delete-error/test.toml @@ -1,8 +1,4 @@ Cloud = false -Badness = "When the backend rejects a delete with an error other than not-found or permission-denied, deploy and destroy drop the resource from state and succeed, so the job stays in the workspace untracked. They should fail with the delete error and keep the resource in state, as the DMS=true run does." - -# The DMS=true run already fails on the rejected delete, so it is excluded until both agree. -EnvMatrix.DMS = [] Ignore = [ "databricks.yml", diff --git a/acceptance/bundle/resources/materialization_sets/settled_failure/out.test.toml b/acceptance/bundle/resources/materialization_sets/settled_failure/out.test.toml index 19b5b15d11f..a927a5fbc06 100644 --- a/acceptance/bundle/resources/materialization_sets/settled_failure/out.test.toml +++ b/acceptance/bundle/resources/materialization_sets/settled_failure/out.test.toml @@ -1,2 +1,2 @@ Cloud = false -EnvMatrix.DMS = [""] +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/materialization_sets/settled_failure/output.txt b/acceptance/bundle/resources/materialization_sets/settled_failure/output.txt index 226455d7831..8c1ce351601 100644 --- a/acceptance/bundle/resources/materialization_sets/settled_failure/output.txt +++ b/acceptance/bundle/resources/materialization_sets/settled_failure/output.txt @@ -31,17 +31,11 @@ Files: 2 uploaded, 0 deleted >>> set_action update -=== The delete settles FAILED the same way, and here the engine decides what the user sees: +=== The delete settles FAILED the same way: the destroy fails with the operation's error and -=== its destroy step forgives a delete error matching none of the cases it knows, so the +=== keeps the set, and the features that depend on it, in state. -=== destroy reports success and drops the state while the set stays in the workspace. The leg - -=== with deployment-history recording takes the one branch that records and returns the - -=== failure, which is why this case runs on the other leg only. - ->>> [CLI] bundle destroy --auto-approve +>>> musterr [CLI] bundle destroy --auto-approve The following resources will be deleted: delete resources.features.failfeat delete resources.features.okfeat @@ -54,4 +48,9 @@ Deleting a Feature View that a FeatureSpec serves is not blocked, and leaves the All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-matset-settled-[UNIQUE_NAME]/default -Destroy: 3 deleted +Error: cannot delete resources.materialization_sets.set1: deleting id=[UUID][0]: materialization set [UUID][0]: operation failed: [INTERNAL_ERROR] Deleted 0 of 2 materialized features in materialization set '[UUID][0]'. The operation's progress lists which deletion succeeded, which failed and why.; members left unchanged: [UUID][1] (INTERNAL_ERROR): Failed to delete materialized feature '[UUID][1]'. If the issue persists, please retry or contact support.; [UUID][2] (INTERNAL_ERROR): Failed to delete materialized feature '[UUID][2]'. If the issue persists, please retry or contact support. + +Error: cannot delete resources.features.okfeat: dependency failed: resources.materialization_sets.set1 + +Error: cannot delete resources.features.failfeat: dependency failed: resources.materialization_sets.set1 + diff --git a/acceptance/bundle/resources/materialization_sets/settled_failure/script b/acceptance/bundle/resources/materialization_sets/settled_failure/script index 3e5a2bf73af..3c03ba5b54d 100644 --- a/acceptance/bundle/resources/materialization_sets/settled_failure/script +++ b/acceptance/bundle/resources/materialization_sets/settled_failure/script @@ -26,11 +26,8 @@ title "Nothing was written, so the removal is still pending" trace $CLI bundle plan -o json > out.plan.json trace set_action -title "The delete settles FAILED the same way, and here the engine decides what the user sees:" -title "its destroy step forgives a delete error matching none of the cases it knows, so the" -title "destroy reports success and drops the state while the set stays in the workspace. The leg" -title "with deployment-history recording takes the one branch that records and returns the" -title "failure, which is why this case runs on the other leg only." -trace $CLI bundle destroy --auto-approve +title "The delete settles FAILED the same way: the destroy fails with the operation's error and" +title "keeps the set, and the features that depend on it, in state." +trace musterr $CLI bundle destroy --auto-approve rm -f out.requests.txt out.plan.json diff --git a/acceptance/bundle/resources/materialization_sets/settled_failure/test.toml b/acceptance/bundle/resources/materialization_sets/settled_failure/test.toml index 61fdc6235a0..6b87966d934 100644 --- a/acceptance/bundle/resources/materialization_sets/settled_failure/test.toml +++ b/acceptance/bundle/resources/materialization_sets/settled_failure/test.toml @@ -1,8 +1,3 @@ -# Pinned to the leg without deployment-history recording, where the engine's destroy step forgives -# a delete error it cannot classify. With recording on it takes the branch that records the failure -# and returns it, so the destroy fails instead and the two legs cannot share one golden. -EnvMatrix.DMS = [""] - # Local only, and not because the claims are redundant: the failure is produced by a marker the # fake looks for in a feature name, since a real teardown fails on infrastructure no request can # ask for. Against a workspace this case would simply succeed. diff --git a/bundle/direct/apply.go b/bundle/direct/apply.go index 2683c6c1532..f0e56c82bed 100644 --- a/bundle/direct/apply.go +++ b/bundle/direct/apply.go @@ -312,8 +312,7 @@ func (d *DeploymentUnit) Delete(ctx context.Context, db *dstate.DeploymentState, log.Warnf(ctx, "Ignoring permission error when deleting %s id=%s: %s", d.ResourceKey, oldID, err) } else if d.deleteConfirmedGone(ctx, oldID) { log.Warnf(ctx, "Treating %s id=%s as already deleted despite delete error: %s", d.ResourceKey, oldID, err) - } else if db.RecordsHistory() { - // When using the deployment metadata service, record the error. + } else { err = fmt.Errorf("deleting id=%s: %w", oldID, err) db.RecordFailure(d.ResourceKey, oldID, err) return err From 325326cdceced7bc7498ceffccfa0204879efce8 Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Tue, 24 Nov 2026 15:13:10 +0000 Subject: [PATCH 2/5] Add changelog entry Co-authored-by: Isaac --- .nextchanges/bundles/delete-error.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .nextchanges/bundles/delete-error.md diff --git a/.nextchanges/bundles/delete-error.md b/.nextchanges/bundles/delete-error.md new file mode 100644 index 00000000000..5caec41f59a --- /dev/null +++ b/.nextchanges/bundles/delete-error.md @@ -0,0 +1 @@ +* Fix `bundle deploy` and `bundle destroy` reporting success and dropping a resource from state when the backend rejects its delete; the resource stayed in the workspace untracked ([#7931](https://github.com/databricks/cli/pull/7931)). ([#7931](https://github.com/databricks/cli/pull/7931)) From 471561717e978a82fb2456d0f790965013528987 Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Tue, 24 Nov 2026 15:14:27 +0000 Subject: [PATCH 3/5] Fix duplicated PR link in changelog entry Co-authored-by: Isaac --- .nextchanges/bundles/delete-error.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/bundles/delete-error.md b/.nextchanges/bundles/delete-error.md index 5caec41f59a..cac8754c047 100644 --- a/.nextchanges/bundles/delete-error.md +++ b/.nextchanges/bundles/delete-error.md @@ -1 +1 @@ -* Fix `bundle deploy` and `bundle destroy` reporting success and dropping a resource from state when the backend rejects its delete; the resource stayed in the workspace untracked ([#7931](https://github.com/databricks/cli/pull/7931)). ([#7931](https://github.com/databricks/cli/pull/7931)) +* Fix `bundle deploy` and `bundle destroy` reporting success and dropping a resource from state when the backend rejects its delete; the resource stayed in the workspace untracked. ([#7931](https://github.com/databricks/cli/pull/7931)) From 7c6fe4c2272e874377eb9f587a4d908a86cacbc0 Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Tue, 24 Nov 2026 15:19:32 +0000 Subject: [PATCH 4/5] acc: assert the failure and the remaining state in bundle/destroy/delete-error Co-authored-by: Isaac --- .nextchanges/bundles/delete-error.md | 2 +- acceptance/bundle/destroy/delete-error/output.txt | 12 ++++-------- acceptance/bundle/destroy/delete-error/script | 6 +++--- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.nextchanges/bundles/delete-error.md b/.nextchanges/bundles/delete-error.md index cac8754c047..707b065ebb7 100644 --- a/.nextchanges/bundles/delete-error.md +++ b/.nextchanges/bundles/delete-error.md @@ -1 +1 @@ -* Fix `bundle deploy` and `bundle destroy` reporting success and dropping a resource from state when the backend rejects its delete; the resource stayed in the workspace untracked. ([#7931](https://github.com/databricks/cli/pull/7931)) +* Fix `bundle deploy` and `bundle destroy` without deployment history reporting success and dropping a resource from state when the backend rejects its delete; the resource stayed in the workspace untracked. ([#7931](https://github.com/databricks/cli/pull/7931)) diff --git a/acceptance/bundle/destroy/delete-error/output.txt b/acceptance/bundle/destroy/delete-error/output.txt index 2dc2635a558..8cf0d868f6c 100644 --- a/acceptance/bundle/destroy/delete-error/output.txt +++ b/acceptance/bundle/destroy/delete-error/output.txt @@ -8,7 +8,7 @@ Resources: 2 created, 0 changed, 0 deleted, 0 unchanged === deploy: removing bar from config, its delete is rejected with 400 ->>> [CLI] bundle deploy +>>> musterr [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/delete-error-[UNIQUE_NAME]/default/files... Error: cannot delete resources.jobs.bar: deleting id=[BAR_ID]: Fault injected by test. (400 INVALID_PARAMETER_VALUE) @@ -19,8 +19,6 @@ API message: Fault injected by test. Files: 1 uploaded, 0 deleted -Exit code: 1 - >>> [CLI] jobs get [BAR_ID] bar-[UNIQUE_NAME] @@ -30,7 +28,7 @@ resources.jobs.foo === destroy: the delete of foo is rejected with 400 ->>> [CLI] bundle destroy --auto-approve +>>> musterr [CLI] bundle destroy --auto-approve The following resources will be deleted: delete resources.jobs.bar delete resources.jobs.foo @@ -45,10 +43,8 @@ API error_code: INVALID_PARAMETER_VALUE API message: Fault injected by test. -Exit code: 1 - >>> [CLI] jobs get [FOO_ID] foo-[UNIQUE_NAME] ->>> find.py \.databricks/.*resources.*\.json -.databricks/bundle/default/resources.json +>>> print_state.py +resources.jobs.foo diff --git a/acceptance/bundle/destroy/delete-error/script b/acceptance/bundle/destroy/delete-error/script index aae9ab2a922..fdbb9152510 100644 --- a/acceptance/bundle/destroy/delete-error/script +++ b/acceptance/bundle/destroy/delete-error/script @@ -8,12 +8,12 @@ update_file.py databricks.yml " bar: name: bar-$UNIQUE_NAME " "" fault.py "POST /api/2.2/jobs/delete" 400 0 1 INVALID_PARAMETER_VALUE -errcode trace $CLI bundle deploy +trace musterr $CLI bundle deploy trace $CLI jobs get $bar_id | jq -r .settings.name trace print_state.py | jq -r '.state | keys[]' title "destroy: the delete of foo is rejected with 400" fault.py --body-contains "\"job_id\":$foo_id}" "POST /api/2.2/jobs/delete" 400 0 1 INVALID_PARAMETER_VALUE -errcode trace $CLI bundle destroy --auto-approve +trace musterr $CLI bundle destroy --auto-approve trace $CLI jobs get $foo_id | jq -r .settings.name -trace find.py '\.databricks/.*resources.*\.json' +trace print_state.py | jq -r '.state | keys[]' From 2c87d47a65b53b386c204fe72b9a37381366f595 Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Tue, 24 Nov 2026 17:04:10 +0000 Subject: [PATCH 5/5] acc: sort the destroy errors in settled_failure, which arrive in either order Co-authored-by: Isaac --- .../settled_failure/output.txt | 14 +++++++------- .../materialization_sets/settled_failure/script | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/acceptance/bundle/resources/materialization_sets/settled_failure/output.txt b/acceptance/bundle/resources/materialization_sets/settled_failure/output.txt index 0ad3f209a76..4cbcdd5dedd 100644 --- a/acceptance/bundle/resources/materialization_sets/settled_failure/output.txt +++ b/acceptance/bundle/resources/materialization_sets/settled_failure/output.txt @@ -41,18 +41,18 @@ The following resources will be deleted: delete resources.features.okfeat delete resources.materialization_sets.set1 -This action will result in the deletion of the following Feature Views. -Deleting a Feature View that a FeatureSpec serves is not blocked, and leaves the FeatureSpec stale: - delete resources.features.failfeat - delete resources.features.okfeat - All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-matset-settled-[UNIQUE_NAME]/default -Error: cannot delete resources.materialization_sets.set1: deleting id=[UUID][0]: materialization set [UUID][0]: operation failed: [INTERNAL_ERROR] Deleted 0 of 2 materialized features in materialization set '[UUID][0]'. The operation's progress lists which deletion succeeded, which failed and why.; members left unchanged: [UUID][1] (INTERNAL_ERROR): Failed to delete materialized feature '[UUID][1]'. If the issue persists, please retry or contact support.; [UUID][2] (INTERNAL_ERROR): Failed to delete materialized feature '[UUID][2]'. If the issue persists, please retry or contact support. +Error: cannot delete resources.features.failfeat: dependency failed: resources.materialization_sets.set1 Error: cannot delete resources.features.okfeat: dependency failed: resources.materialization_sets.set1 -Error: cannot delete resources.features.failfeat: dependency failed: resources.materialization_sets.set1 +Error: cannot delete resources.materialization_sets.set1: deleting id=[UUID][0]: materialization set [UUID][0]: operation failed: [INTERNAL_ERROR] Deleted 0 of 2 materialized features in materialization set '[UUID][0]'. The operation's progress lists which deletion succeeded, which failed and why.; members left unchanged: [UUID][1] (INTERNAL_ERROR): Failed to delete materialized feature '[UUID][1]'. If the issue persists, please retry or contact support.; [UUID][2] (INTERNAL_ERROR): Failed to delete materialized feature '[UUID][2]'. If the issue persists, please retry or contact support. + +This action will result in the deletion of the following Feature Views. +Deleting a Feature View that a FeatureSpec serves is not blocked, and leaves the FeatureSpec stale: + delete resources.features.failfeat + delete resources.features.okfeat >>> print_state.py diff --git a/acceptance/bundle/resources/materialization_sets/settled_failure/script b/acceptance/bundle/resources/materialization_sets/settled_failure/script index 756624c484a..4e454250aac 100644 --- a/acceptance/bundle/resources/materialization_sets/settled_failure/script +++ b/acceptance/bundle/resources/materialization_sets/settled_failure/script @@ -28,7 +28,8 @@ trace set_action title "The delete settles FAILED the same way: the destroy fails with the operation's error and" title "keeps the set, and the features that depend on it, in state." -trace musterr $CLI bundle destroy --auto-approve +# The two dependency errors are reported in either order. +trace musterr $CLI bundle destroy --auto-approve 2>&1 | sort_blocks.py trace print_state.py | gron.py | grep __id__ rm -f out.requests.txt out.plan.json