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/delete-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* 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))
2 changes: 1 addition & 1 deletion acceptance/bundle/destroy/delete-error/out.test.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Cloud = false
EnvMatrix.DMS = []
EnvMatrix.DMS = ["", "true"]
26 changes: 20 additions & 6 deletions acceptance/bundle/destroy/delete-error/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,43 @@ 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...
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

>>> [CLI] jobs get [BAR_ID]
json.settings.name = "bar-[UNIQUE_NAME]";

>>> 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

>>> [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

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.


>>> [CLI] jobs get [FOO_ID]
json.settings.name = "foo-[UNIQUE_NAME]";

>>> find.py \.databricks/.*resources.*\.json
>>> print_state.py
json.state.resources.jobs.foo.__id__ = "[FOO_ID]";
6 changes: 3 additions & 3 deletions acceptance/bundle/destroy/delete-error/script
Original file line number Diff line number Diff line change
Expand Up @@ -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 | gron.py | grep settings.name
trace print_state.py | gron.py | grep __id__

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 | gron.py | grep settings.name
trace find.py '\.databricks/.*resources.*\.json'
trace print_state.py | gron.py | grep __id__
4 changes: 0 additions & 4 deletions acceptance/bundle/destroy/delete-error/test.toml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Cloud = false
EnvMatrix.DMS = [""]
EnvMatrix.DMS = ["", "true"]
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,31 @@ 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
delete resources.materialization_sets.set1

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

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

All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-matset-settled-[UNIQUE_NAME]/default

Destroy: 3 deleted
>>> 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]";
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ 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."
# 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
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
Badness = "Without deployment-history recording, destroy swallows a delete error it cannot classify (DeploymentUnit.Delete in bundle/direct/apply.go logs nothing and drops the state): it prints 'Destroy: 3 deleted' while the materialization set is still in the workspace. Destroy should fail with the delete error, as it does with recording on."

# 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.
Expand Down
3 changes: 1 addition & 2 deletions bundle/direct/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,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
Expand Down
Loading