diff --git a/.nextchanges/bundles/delete-error.md b/.nextchanges/bundles/delete-error.md new file mode 100644 index 00000000000..707b065ebb7 --- /dev/null +++ b/.nextchanges/bundles/delete-error.md @@ -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)) 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 9bcc24e73d7..dabd65e5fbb 100644 --- a/acceptance/bundle/destroy/delete-error/output.txt +++ b/acceptance/bundle/destroy/delete-error/output.txt @@ -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]"; diff --git a/acceptance/bundle/destroy/delete-error/script b/acceptance/bundle/destroy/delete-error/script index f020cc4be9c..ae4c5876a1f 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 | 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__ diff --git a/acceptance/bundle/destroy/delete-error/test.toml b/acceptance/bundle/destroy/delete-error/test.toml deleted file mode 100644 index fd09ad4aa2e..00000000000 --- a/acceptance/bundle/destroy/delete-error/test.toml +++ /dev/null @@ -1,4 +0,0 @@ -Badness = "When the backend rejects a delete and a re-read does not confirm the resource is gone, 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 = [] 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..4cbcdd5dedd 100644 --- a/acceptance/bundle/resources/materialization_sets/settled_failure/output.txt +++ b/acceptance/bundle/resources/materialization_sets/settled_failure/output.txt @@ -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]"; diff --git a/acceptance/bundle/resources/materialization_sets/settled_failure/script b/acceptance/bundle/resources/materialization_sets/settled_failure/script index 3e5a2bf73af..4e454250aac 100644 --- a/acceptance/bundle/resources/materialization_sets/settled_failure/script +++ b/acceptance/bundle/resources/materialization_sets/settled_failure/script @@ -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 diff --git a/acceptance/bundle/resources/materialization_sets/settled_failure/test.toml b/acceptance/bundle/resources/materialization_sets/settled_failure/test.toml index f913450f80f..6b87966d934 100644 --- a/acceptance/bundle/resources/materialization_sets/settled_failure/test.toml +++ b/acceptance/bundle/resources/materialization_sets/settled_failure/test.toml @@ -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. diff --git a/bundle/direct/apply.go b/bundle/direct/apply.go index b558d667c1a..2d1385ca0ac 100644 --- a/bundle/direct/apply.go +++ b/bundle/direct/apply.go @@ -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