Skip to content

direct: fail deploy and destroy when a resource delete is rejected - #7931

Open
denik wants to merge 7 commits into
denik/cov-delete-err-testfrom
denik/cov-delete-err-fix
Open

denik wants to merge 7 commits into
denik/cov-delete-err-testfrom
denik/cov-delete-err-fix

Conversation

@denik

@denik denik commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Changes

(*DeploymentUnit).Delete returns the delete error again when the backend rejects a delete with an error that is not missing, managed-by-parent or permission-denied, and a re-read does not show the resource gone. Before, without deployment history, it fell through to dropping the resource from state: bundle destroy and bundle deploy (for a resource removed from the config) reported success while the resource stayed in the workspace, untracked.

This is a regression from #6094 (7bf1485), which changed the final

} else {
	return fmt.Errorf("deleting id=%s: %w", oldID, err)
}

into } else if db.IsDeploymentMetadataService() { ...; return err } (renamed to RecordsHistory in #7169), so the case without deployment history lost its return.

Fix shape: I kept the pre-#6094 behavior. The error is returned for every run, with or without deployment history, and the resource stays in state so the next deploy or destroy retries the delete. RecordFailure is still called unconditionally in that branch; it is already a no-op when history is not recorded, so nothing extra is written for runs without history.

Tests:

  • bundle/destroy/delete-error (from acc: record that a rejected delete drops the resource from state in bundle/destroy/delete-error #7930): output now shows both commands failing with the delete error and the job kept in state; Badness removed and the DMS=true variant re-enabled (both variants now share one golden).

  • bundle/resources/materialization_sets/settled_failure: its destroy step recorded the old behavior ("forgives a delete error ... drops the state while the set stays in the workspace") and was pinned to DMS="" for that reason. It now asserts the destroy fails (musterr) and runs on both variants.

  • In the fix PR, bundle/destroy/delete-error asserts the failures with musterr and prints the state after the partial destroy: foo (rejected) is kept and bar (deleted) is gone.

Scope notes:

  • Any delete error that is not missing, managed-by-parent or permission-denied, and that a re-read cannot confirm as gone, now fails the command on runs without deployment history, as it did before bundle: record and read deployment state via DMS #6094 and as it already does with history on. A resource type whose backend reports an in-progress or already-done teardown with some other error would need its IsGone (or the error classification) taught about it; I did not find such a case among the existing tests.
  • When a destroy partly fails, destroyCore returns before printing the Destroy: N deleted summary. That is existing behavior for every delete error (including runs with history) and is left for a separate change.

Overlap: #7496 changes the same lines and keeps the fallthrough (with a warning and a "removed from state" count). This PR removes the fallthrough instead; the two need to be reconciled whichever lands first.

Why

A destroy that reports success while leaving resources in the workspace is worse than a failure: the user has no state and no message pointing at the leftover resource.

This PR was created by analyzing coverage gaps.

Coverage: bundle/direct/apply.go, (*DeploymentUnit).Delete, the branch for a delete error that is not missing, managed-by-parent or permission-denied.

Tests

go test ./acceptance -run 'TestAccept/bundle/destroy/delete-error' and TestAccept/bundle/resources/materialization_sets; go test ./bundle/....

AI agent (opus5.5, isaac_claude)

This pull request and its description were written by Isaac.

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 <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
…ete-error

Co-authored-by: Isaac <no-reply@databricks.com>
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Commit: 7fda907d1 | Workflow run

Regression test report

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

4 tests: regression=2 unreleased=0 coverage=2 failing=0
test branch main (0c71683) latest (v1.28.0)
TestAccept/bundle/destroy/delete-error/DMS= ✅ ❌ ❌
TestAccept/bundle/destroy/delete-error/DMS=true ✅ ✅ ✅
TestAccept/bundle/resources/materialization_sets/settled_failure/DMS= ✅ ❌ ❌
TestAccept/bundle/resources/materialization_sets/settled_failure/DMS=true ✅ ✅ ✅
TestAccept/bundle/destroy/delete-error/DMS=: branch ✅ | main (0c71683) ❌ | latest (v1.28.0) ❌

main (0c71683):

acceptance_test.go:1402: Diff:
        --- bundle/destroy/delete-error/output.txt
        +++ /tmp/TestAcceptbundledestroydelete-errorDMS=1883153541/002/output.txt
        @@ -10,41 +10,10 @@
         
         >>> 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)
        -
        -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.
        -
        +Deleted jobs.bar
         Files: 1 uploaded, 0 deleted
        +Resources: 0 created, 0 changed, 1 deleted, 1 unchanged
         
        ->>> [CLI] jobs get [BAR_ID]
        -json.settings.name = "bar-[UNIQUE_NAME]";
        +Unexpected success
         
        ->>> print_state.py
        -json.state.resources.jobs.bar.__id__ = "[BAR_ID]";
        -json.state.resources.jobs.foo.__id__ = "[FOO_ID]";
        -
        -=== destroy: the delete of foo is rejected with 400
        -
        ->>> musterr [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
        -
        -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.
        -
        -
        ->>> [CLI] jobs get [FOO_ID]
        -json.settings.name = "foo-[UNIQUE_NAME]";
        -
        ->>> print_state.py
        -json.state.resources.jobs.foo.__id__ = "[FOO_ID]";
        +Exit code: 1
        
    acceptance_test.go:1192: Test produced unexpected files:
        .databricks/.gitignore
        .databricks/bundle/default/deployment.json
        .databricks/bundle/default/released-deploy-locks.json
        .databricks/bundle/default/resources.json
        .databricks/bundle/default/sync-snapshots/dd042e40d2625286.json

latest (v1.28.0):

acceptance_test.go:1402: Diff:
        --- bundle/destroy/delete-error/output.txt
        +++ /tmp/TestAcceptbundledestroydelete-errorDMS=1076115312/002/output.txt
        @@ -10,41 +10,10 @@
         
         >>> 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)
        -
        -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.
        -
        +Deleted jobs.bar
         Files: 1 uploaded, 0 deleted
        +Resources: 0 created, 0 changed, 1 deleted, 1 unchanged
         
        ->>> [CLI] jobs get [BAR_ID]
        -json.settings.name = "bar-[UNIQUE_NAME]";
        +Unexpected success
         
        ->>> print_state.py
        -json.state.resources.jobs.bar.__id__ = "[BAR_ID]";
        -json.state.resources.jobs.foo.__id__ = "[FOO_ID]";
        -
        -=== destroy: the delete of foo is rejected with 400
        -
        ->>> musterr [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
        -
        -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.
        -
        -
        ->>> [CLI] jobs get [FOO_ID]
        -json.settings.name = "foo-[UNIQUE_NAME]";
        -
        ->>> print_state.py
        -json.state.resources.jobs.foo.__id__ = "[FOO_ID]";
        +Exit code: 1
        
    acceptance_test.go:1192: Test produced unexpected files:
        .databricks/.gitignore
        .databricks/bundle/default/deployment.json
        .databricks/bundle/default/released-deploy-locks.json
        .databricks/bundle/default/resources.json
        .databricks/bundle/default/sync-snapshots/f837a93b38c1a21f.json
TestAccept/bundle/resources/materialization_sets/settled_failure/DMS=: branch ✅ | main (0c71683) ❌ | latest (v1.28.0) ❌

main (0c71683):

acceptance_test.go:1402: Diff:
        --- bundle/resources/materialization_sets/settled_failure/output.txt
        +++ /tmp/TestAcceptbundleresourcesmaterialization_setssettled_failure3592193155/002/output.txt
        @@ -34,7 +34,6 @@
         === The delete settles FAILED the same way: the destroy fails with the operation's error and
         
         === keeps the set, and the features that depend on it, in state.
        -
         >>> musterr [CLI] bundle destroy --auto-approve
         The following resources will be deleted:
           delete resources.features.failfeat
        @@ -43,19 +42,14 @@
         
         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.features.failfeat: dependency failed: resources.materialization_sets.set1
        +Destroy: 3 deleted
         
        -Error: cannot delete resources.features.okfeat: 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
         
        +Unexpected success
         
        ->>> print_state.py
        -json.state.resources.features.failfeat.__id__ = "main.myschema.teardown_fails_[UNIQUE_NAME]";
        -json.state.resources.features.okfeat.__id__ = "main.myschema.ok_[UNIQUE_NAME]";
        -json.state.resources.materialization_sets.set1.__id__ = "[UUID][0]";
        +
        +Exit code: 1
        
    acceptance_test.go:1384: Unexpected output file: out.plan.json
        pathRef: bundle/resources/materialization_sets/settled_failure/out.plan.json
        pathNew: /tmp/TestAcceptbundleresourcesmaterialization_setssettled_failure3592193155/001/out.plan.json
    acceptance_test.go:1192: Test produced unexpected files:
        out.plan.json
FAIL

latest (v1.28.0):

acceptance_test.go:1402: Diff:
        --- bundle/resources/materialization_sets/settled_failure/output.txt
        +++ /tmp/TestAcceptbundleresourcesmaterialization_setssettled_failure4150972906/002/output.txt
        @@ -34,7 +34,6 @@
         === The delete settles FAILED the same way: the destroy fails with the operation's error and
         
         === keeps the set, and the features that depend on it, in state.
        -
         >>> musterr [CLI] bundle destroy --auto-approve
         The following resources will be deleted:
           delete resources.features.failfeat
        @@ -43,19 +42,14 @@
         
         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.features.failfeat: dependency failed: resources.materialization_sets.set1
        +Destroy: 3 deleted
         
        -Error: cannot delete resources.features.okfeat: 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
         
        +Unexpected success
         
        ->>> print_state.py
        -json.state.resources.features.failfeat.__id__ = "main.myschema.teardown_fails_[UNIQUE_NAME]";
        -json.state.resources.features.okfeat.__id__ = "main.myschema.ok_[UNIQUE_NAME]";
        -json.state.resources.materialization_sets.set1.__id__ = "[UUID][0]";
        +
        +Exit code: 1
        
    acceptance_test.go:1384: Unexpected output file: out.plan.json
        pathRef: bundle/resources/materialization_sets/settled_failure/out.plan.json
        pathNew: /tmp/TestAcceptbundleresourcesmaterialization_setssettled_failure4150972906/001/out.plan.json
    acceptance_test.go:1192: Test produced unexpected files:
        out.plan.json

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: 7fda907

Run: 45580462332

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 272 21 5:48
💚​ aws-windows-latest-4core-16gb 1 274 19 3:24
💚​ azure linux-2core-8gb 1 271 21 4:40
💚​ azure-windows-latest-4core-16gb 1 273 19 2:26
💚​ gcp linux-2core-8gb 1 272 21 5:19
💚​ gcp-windows-latest-4core-16gb 1 274 19 3:59
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 6 slowest tests (at least 2 minutes):
duration env testname
4:12 aws linux-2core-8gb TestAccept
3:59 gcp linux-2core-8gb TestAccept
3:21 azure linux-2core-8gb TestAccept
2:12 gcp-windows-latest-4core-16gb TestAccept
2:09 aws-windows-latest-4core-16gb TestAccept
2:00 azure-windows-latest-4core-16gb TestAccept

@denik
denik marked this pull request as ready for review November 24, 2026 15:43
@denik
denik requested review from a team as code owners November 24, 2026 15:43

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review at 7c6fe4c. Each finding was verified against the code.

No blocking issues found. 1 non-blocking comment(s) below.

This PR makes (*DeploymentUnit).Delete return the delete error on runs without deployment history too, so a rejected delete fails bundle deploy/bundle destroy and the resource stays in state. That restores the behavior from before #6094. The change in apply.go is right: RecordFailure already does nothing when history isn't recorded, and deleteConfirmedGone is still checked first. One test gap remains: the settled_failure golden doesn't show the state that its new title describes.

Co-authored-by: Isaac <no-reply@databricks.com>
…er order

Co-authored-by: Isaac <no-reply@databricks.com>
settled_failure/test.toml: #7919 added a Badness for the bug this PR fixes;
keep this branch's version, which drops it with the DMS pin.

Co-authored-by: Isaac <no-reply@databricks.com>

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.

3 participants