diff --git a/.nextchanges/bundles/schema-volume-identity.md b/.nextchanges/bundles/schema-volume-identity.md new file mode 100644 index 00000000000..4f70baad412 --- /dev/null +++ b/.nextchanges/bundles/schema-volume-identity.md @@ -0,0 +1 @@ +* The direct deployment engine no longer updates or deletes a schema or volume at the bundle's recorded name when its `schema_id` or `volume_id` differs from the recorded one: `bundle deploy` plans a create instead, and `bundle destroy` only drops the bundle's entry from the state, with a warning. A schema or volume deleted and created again outside the bundle is therefore no longer taken for the bundle's: deploy fails on its name until it is bound again with `bundle deployment unbind` and `bundle deployment bind`. ([#8056](https://github.com/databricks/cli/pull/8056)) diff --git a/acceptance/bin/replay_tfstate.py b/acceptance/bin/replay_tfstate.py index 598f09215fb..d481c050d3e 100755 --- a/acceptance/bin/replay_tfstate.py +++ b/acceptance/bin/replay_tfstate.py @@ -125,7 +125,10 @@ def main(): continue for nf in NAME_FIELDS: if attrs.get(nf): - name_to_attrs[str(attrs[nf])] = attrs + # Keyed lowercased: UC lowercases names (a schema created as MySchema is stored as + # myschema), so the tfstate may hold the lowercased form of the name the create + # request sent. + name_to_attrs[str(attrs[nf]).lower()] = attrs id_map = {} for req in requests: @@ -149,10 +152,10 @@ def main(): # map its recorded id to the freshly minted one. create_name = None if isinstance(body, dict): - create_name = next((str(body[nf]) for nf in NAME_FIELDS if body.get(nf)), None) + create_name = next((str(body[nf]).lower() for nf in NAME_FIELDS if body.get(nf)), None) if req["method"] == "POST" and create_name in name_to_attrs: attrs = name_to_attrs[create_name] - if str(attrs["id"]) != create_name: + if str(attrs["id"]).lower() != create_name: # Backend-minted primary id (jobs, pipelines, volumes): map recorded -> minted. new_id = next((str(resp[f]) for f in ID_FIELDS if f in resp), None) if new_id is None: diff --git a/acceptance/bundle/resources/schemas/destroy_with_other_at_recorded_name/databricks.yml.tmpl b/acceptance/bundle/resources/schemas/destroy_with_other_at_recorded_name/databricks.yml.tmpl new file mode 100644 index 00000000000..d73aacf0d14 --- /dev/null +++ b/acceptance/bundle/resources/schemas/destroy_with_other_at_recorded_name/databricks.yml.tmpl @@ -0,0 +1,9 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +resources: + schemas: + schema1: + catalog_name: main + name: test-schema-$UNIQUE_NAME + comment: c1 diff --git a/acceptance/bundle/resources/schemas/destroy_with_other_at_recorded_name/out.test.toml b/acceptance/bundle/resources/schemas/destroy_with_other_at_recorded_name/out.test.toml new file mode 100644 index 00000000000..0f167effef1 --- /dev/null +++ b/acceptance/bundle/resources/schemas/destroy_with_other_at_recorded_name/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/schemas/destroy_with_other_at_recorded_name/output.txt b/acceptance/bundle/resources/schemas/destroy_with_other_at_recorded_name/output.txt new file mode 100644 index 00000000000..39705caa888 --- /dev/null +++ b/acceptance/bundle/resources/schemas/destroy_with_other_at_recorded_name/output.txt @@ -0,0 +1,49 @@ + +=== Deploy a schema + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Created schemas.schema1 +Files: 2 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +=== Out of band, rename the schema away, and create another one under its name + +>>> [CLI] schemas update main.test-schema-[UNIQUE_NAME] --new-name test-schema-moved-[UNIQUE_NAME] +{ + "full_name": "main.test-schema-moved-[UNIQUE_NAME]", + "schema_id": "[SCHEMA_ID]" +} + +=== Destroy sends no delete for the other schema: it warns and only drops the bundle's entry from the state + +>>> [CLI] bundle destroy --auto-approve +Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds another object: its schema_id is "[FOREIGN_SCHEMA_ID]", not "[SCHEMA_ID]" as recorded, so no delete is sent for it, and its entry is dropped from the deployment state. If the bundle's was renamed outside the bundle, it is left in place under its new name: delete it outside the bundle. If this object is the bundle's (deleted and created again outside the bundle), delete it outside the bundle. + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default + +Destroy: 0 deleted + +>>> print_requests.py //unity-catalog + +>>> [CLI] bundle summary --output json +{ + "id": null, + "modified_status": "created" +} + +=== The other schema is left alone + +>>> [CLI] schemas get main.test-schema-[UNIQUE_NAME] +{ + "full_name": "main.test-schema-[UNIQUE_NAME]", + "schema_id": "[FOREIGN_SCHEMA_ID]" +} + +=== The bundle's renamed schema is left behind + +>>> [CLI] schemas get main.test-schema-moved-[UNIQUE_NAME] +{ + "full_name": "main.test-schema-moved-[UNIQUE_NAME]", + "schema_id": "[SCHEMA_ID]" +} diff --git a/acceptance/bundle/resources/schemas/destroy_with_other_at_recorded_name/script b/acceptance/bundle/resources/schemas/destroy_with_other_at_recorded_name/script new file mode 100644 index 00000000000..f5efb87ee69 --- /dev/null +++ b/acceptance/bundle/resources/schemas/destroy_with_other_at_recorded_name/script @@ -0,0 +1,36 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +SCHEMA="main.test-schema-${UNIQUE_NAME}" +MOVED_SCHEMA="main.test-schema-moved-${UNIQUE_NAME}" + +cleanup() { + # Whatever destroy left behind. + $CLI schemas delete "$MOVED_SCHEMA" --force > LOG.cleanup 2>&1 || true + $CLI schemas delete "$SCHEMA" --force >> LOG.cleanup 2>&1 || true + + # Consume the cleanup's requests so none are left recorded. + print_requests.py //unity-catalog &> LOG.cleanup_requests +} +trap cleanup EXIT + +title "Deploy a schema" +trace $CLI bundle deploy +print_requests.py //unity-catalog &> LOG.deploy_requests +add_repl "$($CLI schemas get "$SCHEMA" | jq -r .schema_id)" SCHEMA_ID + +title "Out of band, rename the schema away, and create another one under its name" +trace $CLI schemas update "$SCHEMA" --new-name "test-schema-moved-${UNIQUE_NAME}" | schema_fields +add_repl "$($CLI schemas create "test-schema-${UNIQUE_NAME}" main | jq -r .schema_id)" FOREIGN_SCHEMA_ID +print_requests.py //unity-catalog &> LOG.oob_requests + +# The config still names the schema at its old name. +title "Destroy sends no delete for the other schema: it warns and only drops the bundle's entry from the state" +trace $CLI bundle destroy --auto-approve +trace print_requests.py //unity-catalog +trace $CLI bundle summary --output json | jq '.resources.schemas.schema1 | {id, modified_status}' + +title "The other schema is left alone" +trace $CLI schemas get "$SCHEMA" | schema_fields + +title "The bundle's renamed schema is left behind" +trace $CLI schemas get "$MOVED_SCHEMA" | schema_fields diff --git a/acceptance/bundle/resources/schemas/destroy_with_other_at_recorded_name/test.toml b/acceptance/bundle/resources/schemas/destroy_with_other_at_recorded_name/test.toml new file mode 100644 index 00000000000..652d759a483 --- /dev/null +++ b/acceptance/bundle/resources/schemas/destroy_with_other_at_recorded_name/test.toml @@ -0,0 +1,8 @@ +Badness = "Destroy does not look for the bundle's schema after a rename out of band: it drops the state entry and leaves the renamed schema behind. It should find it by its schema_id." +Cloud = true + +Ignore = [ + ".databricks", + ".gitignore", + "databricks.yml", +] diff --git a/acceptance/bundle/resources/schemas/foreign_at_recorded_name/databricks-moved.yml.tmpl b/acceptance/bundle/resources/schemas/foreign_at_recorded_name/databricks-moved.yml.tmpl new file mode 100644 index 00000000000..293f74fc08e --- /dev/null +++ b/acceptance/bundle/resources/schemas/foreign_at_recorded_name/databricks-moved.yml.tmpl @@ -0,0 +1,9 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +resources: + schemas: + schema1: + catalog_name: main + name: test-schema-moved-$UNIQUE_NAME + comment: c1 diff --git a/acceptance/bundle/resources/schemas/foreign_at_recorded_name/output.txt b/acceptance/bundle/resources/schemas/foreign_at_recorded_name/output.txt index fcfa9eb6c55..6bd46614493 100644 --- a/acceptance/bundle/resources/schemas/foreign_at_recorded_name/output.txt +++ b/acceptance/bundle/resources/schemas/foreign_at_recorded_name/output.txt @@ -4,7 +4,7 @@ >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Created schemas.schema1 -Files: 2 uploaded, 0 deleted +Files: 3 uploaded, 0 deleted Resources: 1 created, 0 changed, 0 deleted, 0 unchanged === Out of band, rename the schema away, and create another one under its name @@ -15,47 +15,108 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged "schema_id": "[SCHEMA_ID]" } -=== The plan takes the other schema for the bundle's, though its schema_id differs, and plans to update it +=== The other schema has another schema_id, so the plan does not take it for the bundle's: it plans a create >>> [CLI] bundle plan --output json +Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds another object: its schema_id is "[FOREIGN_SCHEMA_ID]", not "[SCHEMA_ID]" as recorded, so this bundle does not take it for its own. If the bundle's was renamed outside the bundle, set its name in the config to the new one. If this object is the bundle's (deleted and created again outside the bundle), run 'bundle deployment unbind' and then 'bundle deployment bind' to manage it again. + { - "resources.schemas.schema1": { - "action": "update", - "new_state": { - "value": { - "catalog_name": "main", - "comment": "c1", - "name": "test-schema-[UNIQUE_NAME]" - } - }, - "remote_state": { - "browse_only": false, + "action": "create", + "new_state": { + "value": { "catalog_name": "main", - "catalog_type": "MANAGED_CATALOG", - "created_by": "[USERNAME]", - "enable_predictive_optimization": "INHERIT", - "full_name": "main.test-schema-[UNIQUE_NAME]", - "name": "test-schema-[UNIQUE_NAME]", - "owner": "[USERNAME]", - "schema_id": "[FOREIGN_SCHEMA_ID]" + "comment": "c1", + "name": "test-schema-[UNIQUE_NAME]" + } + }, + "changes": { + "schema_id": { + "action": "skip", + "reason": "internal_id", + "old": "[SCHEMA_ID]" + } + } +} + +=== Deploy leaves the other schema alone: the create fails on its name + +>>> musterr [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds another object: its schema_id is "[FOREIGN_SCHEMA_ID]", not "[SCHEMA_ID]" as recorded, so this bundle does not take it for its own. If the bundle's was renamed outside the bundle, set its name in the config to the new one. If this object is the bundle's (deleted and created again outside the bundle), run 'bundle deployment unbind' and then 'bundle deployment bind' to manage it again. + +Error: cannot create resources.schemas.schema1: Schema 'test-schema-[UNIQUE_NAME]' already exists (400 SCHEMA_ALREADY_EXISTS) + +Endpoint: POST [DATABRICKS_URL]/api/2.1/unity-catalog/schemas +HTTP Status: 400 Bad Request +API error_code: SCHEMA_ALREADY_EXISTS +API message: Schema 'test-schema-[UNIQUE_NAME]' already exists + +Files: 2 uploaded, 0 deleted + +>>> print_requests.py //unity-catalog +{ + "method": "POST", + "path": "/api/2.1/unity-catalog/schemas", + "body": { + "catalog_name": "main", + "comment": "c1", + "name": "test-schema-[UNIQUE_NAME]" + } +} + +=== Point the config at the bundle's renamed schema: the plan finds it there by its schema_id + +>>> [CLI] bundle plan --output json +{ + "id": "main.test-schema-moved-[UNIQUE_NAME]", + "action": "update_id", + "state_only": true, + "new_state": { + "value": { + "catalog_name": "main", + "comment": "c1", + "name": "test-schema-moved-[UNIQUE_NAME]" + } + }, + "changes": { + "name": { + "action": "skip", + "reason": "remote_already_set", + "old": "test-schema-[UNIQUE_NAME]", + "new": "test-schema-moved-[UNIQUE_NAME]", + "remote": "test-schema-moved-[UNIQUE_NAME]" }, - "changes": { - "comment": { - "action": "update", - "old": "c1", - "new": "c1" - }, - "schema_id": { - "action": "skip", - "reason": "internal_id", - "old": "[SCHEMA_ID]", - "remote": "[FOREIGN_SCHEMA_ID]" - } + "schema_id": { + "action": "skip", + "reason": "internal_id", + "old": "[SCHEMA_ID]", + "remote": "[SCHEMA_ID]" } } } -=== Destroy deletes the other schema +=== Deploy takes the renamed schema for the bundle's, and sends nothing to the other one + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Files: 1 uploaded, 0 deleted +Resources: 0 created, 0 changed, 0 deleted, 1 unchanged + +>>> print_requests.py //unity-catalog + +>>> [CLI] schemas get main.test-schema-moved-[UNIQUE_NAME] +{ + "full_name": "main.test-schema-moved-[UNIQUE_NAME]", + "schema_id": "[SCHEMA_ID]" +} + +>>> [CLI] schemas get main.test-schema-[UNIQUE_NAME] +{ + "full_name": "main.test-schema-[UNIQUE_NAME]", + "schema_id": "[FOREIGN_SCHEMA_ID]" +} + +=== Destroy deletes the bundle's schema at its new name, not the other one >>> [CLI] bundle destroy --auto-approve The following resources will be deleted: @@ -71,19 +132,19 @@ Destroy: 1 deleted >>> print_requests.py //unity-catalog { "method": "DELETE", - "path": "/api/2.1/unity-catalog/schemas/main.test-schema-[UNIQUE_NAME]", + "path": "/api/2.1/unity-catalog/schemas/main.test-schema-moved-[UNIQUE_NAME]", "q": { "force": "true" } } ->>> musterr [CLI] schemas get main.test-schema-[UNIQUE_NAME] -Error: Schema 'main.test-schema-[UNIQUE_NAME]' does not exist. +>>> musterr [CLI] schemas get main.test-schema-moved-[UNIQUE_NAME] +Error: Schema 'main.test-schema-moved-[UNIQUE_NAME]' does not exist. -=== The bundle's own schema is left behind +=== The other schema is left alone ->>> [CLI] schemas get main.test-schema-moved-[UNIQUE_NAME] +>>> [CLI] schemas get main.test-schema-[UNIQUE_NAME] { - "full_name": "main.test-schema-moved-[UNIQUE_NAME]", - "schema_id": "[SCHEMA_ID]" + "full_name": "main.test-schema-[UNIQUE_NAME]", + "schema_id": "[FOREIGN_SCHEMA_ID]" } diff --git a/acceptance/bundle/resources/schemas/foreign_at_recorded_name/script b/acceptance/bundle/resources/schemas/foreign_at_recorded_name/script index d47f32d6805..ab07a2a06e5 100644 --- a/acceptance/bundle/resources/schemas/foreign_at_recorded_name/script +++ b/acceptance/bundle/resources/schemas/foreign_at_recorded_name/script @@ -13,10 +13,6 @@ cleanup() { } trap cleanup EXIT -# Drop the remote_state fields that differ between clouds or from the test server. -plan() { - trace $CLI bundle plan --output json | jq .plan | normalize_uc_payload.py created_at updated_at updated_by metastore_id effective_predictive_optimization_flag storage_location -} title "Deploy a schema" trace $CLI bundle deploy @@ -24,17 +20,31 @@ print_requests.py //unity-catalog &> LOG.deploy_requests add_repl "$($CLI schemas get "$SCHEMA" | jq -r .schema_id)" SCHEMA_ID title "Out of band, rename the schema away, and create another one under its name" -trace $CLI schemas update "$SCHEMA" --new-name "test-schema-moved-${UNIQUE_NAME}" | jq '{full_name, schema_id}' +trace $CLI schemas update "$SCHEMA" --new-name "test-schema-moved-${UNIQUE_NAME}" | schema_fields add_repl "$($CLI schemas create "test-schema-${UNIQUE_NAME}" main | jq -r .schema_id)" FOREIGN_SCHEMA_ID print_requests.py //unity-catalog &> LOG.oob_requests -title "The plan takes the other schema for the bundle's, though its schema_id differs, and plans to update it" -plan +title "The other schema has another schema_id, so the plan does not take it for the bundle's: it plans a create" +trace $CLI bundle plan --output json | plan_filter.py resources.schemas.schema1 + +title "Deploy leaves the other schema alone: the create fails on its name" +trace musterr $CLI bundle deploy +trace print_requests.py //unity-catalog + +title "Point the config at the bundle's renamed schema: the plan finds it there by its schema_id" +envsubst < databricks-moved.yml.tmpl > databricks.yml +trace $CLI bundle plan --output json | plan_filter.py resources.schemas.schema1 + +title "Deploy takes the renamed schema for the bundle's, and sends nothing to the other one" +trace $CLI bundle deploy +trace print_requests.py //unity-catalog +trace $CLI schemas get "$MOVED_SCHEMA" | schema_fields +trace $CLI schemas get "$SCHEMA" | schema_fields -title "Destroy deletes the other schema" +title "Destroy deletes the bundle's schema at its new name, not the other one" trace $CLI bundle destroy --auto-approve trace print_requests.py //unity-catalog -trace musterr $CLI schemas get "$SCHEMA" +trace musterr $CLI schemas get "$MOVED_SCHEMA" -title "The bundle's own schema is left behind" -trace $CLI schemas get "$MOVED_SCHEMA" | jq '{full_name, schema_id}' +title "The other schema is left alone" +trace $CLI schemas get "$SCHEMA" | schema_fields diff --git a/acceptance/bundle/resources/schemas/foreign_at_recorded_name/test.toml b/acceptance/bundle/resources/schemas/foreign_at_recorded_name/test.toml index 434acb5e029..4272a80cf61 100644 --- a/acceptance/bundle/resources/schemas/foreign_at_recorded_name/test.toml +++ b/acceptance/bundle/resources/schemas/foreign_at_recorded_name/test.toml @@ -1,4 +1,3 @@ -Badness = "The plan reads the recorded name and takes whatever schema is there without checking schema_id: a schema someone else created at that name after ours was renamed is planned as an update and then deleted by destroy, while ours is left behind. A schema_id mismatch should mean the bundle's schema is not there, and the plan should look for it by its schema_id." Cloud = true Ignore = [ diff --git a/acceptance/bundle/resources/schemas/recreated_at_recorded_name/databricks.yml.tmpl b/acceptance/bundle/resources/schemas/recreated_at_recorded_name/databricks.yml.tmpl new file mode 100644 index 00000000000..d73aacf0d14 --- /dev/null +++ b/acceptance/bundle/resources/schemas/recreated_at_recorded_name/databricks.yml.tmpl @@ -0,0 +1,9 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +resources: + schemas: + schema1: + catalog_name: main + name: test-schema-$UNIQUE_NAME + comment: c1 diff --git a/acceptance/bundle/resources/schemas/recreated_at_recorded_name/out.test.toml b/acceptance/bundle/resources/schemas/recreated_at_recorded_name/out.test.toml new file mode 100644 index 00000000000..0f167effef1 --- /dev/null +++ b/acceptance/bundle/resources/schemas/recreated_at_recorded_name/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/schemas/recreated_at_recorded_name/output.txt b/acceptance/bundle/resources/schemas/recreated_at_recorded_name/output.txt new file mode 100644 index 00000000000..23082ee9bc2 --- /dev/null +++ b/acceptance/bundle/resources/schemas/recreated_at_recorded_name/output.txt @@ -0,0 +1,73 @@ + +=== Deploy a schema + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Created schemas.schema1 +Files: 2 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +=== Out of band, drop the schema and create it again under the same name + +>>> [CLI] schemas delete main.test-schema-[UNIQUE_NAME] --force + +=== The new schema has another schema_id: the bundle does not take it for its own, and deploy fails on its name + +>>> [CLI] bundle plan +Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds another object: its schema_id is "[NEW_SCHEMA_ID]", not "[SCHEMA_ID]" as recorded, so this bundle does not take it for its own. If the bundle's was renamed outside the bundle, set its name in the config to the new one. If this object is the bundle's (deleted and created again outside the bundle), run 'bundle deployment unbind' and then 'bundle deployment bind' to manage it again. + +create schemas.schema1 + +Plan: 1 to add, 0 to change, 0 to delete, 0 unchanged + +>>> musterr [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Warning: resources.schemas.schema1: id="main.test-schema-[UNIQUE_NAME]" holds another object: its schema_id is "[NEW_SCHEMA_ID]", not "[SCHEMA_ID]" as recorded, so this bundle does not take it for its own. If the bundle's was renamed outside the bundle, set its name in the config to the new one. If this object is the bundle's (deleted and created again outside the bundle), run 'bundle deployment unbind' and then 'bundle deployment bind' to manage it again. + +Error: cannot create resources.schemas.schema1: Schema 'test-schema-[UNIQUE_NAME]' already exists (400 SCHEMA_ALREADY_EXISTS) + +Endpoint: POST [DATABRICKS_URL]/api/2.1/unity-catalog/schemas +HTTP Status: 400 Bad Request +API error_code: SCHEMA_ALREADY_EXISTS +API message: Schema 'test-schema-[UNIQUE_NAME]' already exists + +Files: 2 uploaded, 0 deleted + +>>> print_requests.py //unity-catalog +{ + "method": "POST", + "path": "/api/2.1/unity-catalog/schemas", + "body": { + "catalog_name": "main", + "comment": "c1", + "name": "test-schema-[UNIQUE_NAME]" + } +} + +=== Binding it again makes it the bundle's + +>>> [CLI] bundle deployment unbind schema1 + +>>> [CLI] bundle deployment bind schema1 main.test-schema-[UNIQUE_NAME] --auto-approve +Successfully bound schema with an id 'main.test-schema-[UNIQUE_NAME]' +Run 'bundle deploy' to deploy changes to your workspace + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Updated schemas.schema1 +Files: 0 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 0 unchanged + +>>> [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.schemas.schema1 + +This action will result in the deletion of the following UC schemas. Any underlying data may be lost: + delete resources.schemas.schema1 + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default + +Destroy: 1 deleted diff --git a/acceptance/bundle/resources/schemas/recreated_at_recorded_name/script b/acceptance/bundle/resources/schemas/recreated_at_recorded_name/script new file mode 100644 index 00000000000..5e51f296741 --- /dev/null +++ b/acceptance/bundle/resources/schemas/recreated_at_recorded_name/script @@ -0,0 +1,33 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +SCHEMA="main.test-schema-${UNIQUE_NAME}" + +cleanup() { + trace $CLI bundle destroy --auto-approve + $CLI schemas delete "$SCHEMA" --force > LOG.cleanup 2>&1 || true + + # Consume the destroy's requests so none are left recorded. + print_requests.py //unity-catalog &> LOG.destroy_requests +} +trap cleanup EXIT + +title "Deploy a schema" +trace $CLI bundle deploy +print_requests.py //unity-catalog &> LOG.deploy_requests +add_repl "$($CLI schemas get "$SCHEMA" | jq -r .schema_id)" SCHEMA_ID + +title "Out of band, drop the schema and create it again under the same name" +trace $CLI schemas delete "$SCHEMA" --force +add_repl "$($CLI schemas create "test-schema-${UNIQUE_NAME}" main | jq -r .schema_id)" NEW_SCHEMA_ID +print_requests.py //unity-catalog &> LOG.oob_requests + +title "The new schema has another schema_id: the bundle does not take it for its own, and deploy fails on its name" +trace $CLI bundle plan +trace musterr $CLI bundle deploy +trace print_requests.py //unity-catalog + +title "Binding it again makes it the bundle's" +trace $CLI bundle deployment unbind schema1 +trace $CLI bundle deployment bind schema1 "$SCHEMA" --auto-approve +trace $CLI bundle deploy +trace $CLI bundle plan diff --git a/acceptance/bundle/resources/schemas/recreated_at_recorded_name/test.toml b/acceptance/bundle/resources/schemas/recreated_at_recorded_name/test.toml new file mode 100644 index 00000000000..4272a80cf61 --- /dev/null +++ b/acceptance/bundle/resources/schemas/recreated_at_recorded_name/test.toml @@ -0,0 +1,7 @@ +Cloud = true + +Ignore = [ + ".databricks", + ".gitignore", + "databricks.yml", +] diff --git a/acceptance/bundle/resources/script.prepare b/acceptance/bundle/resources/script.prepare new file mode 100644 index 00000000000..c657433796c --- /dev/null +++ b/acceptance/bundle/resources/script.prepare @@ -0,0 +1,9 @@ +# The *_fields helpers are the allow-lists of fields the acceptance tests assert on. Anything the +# backend returns outside a list is dropped, so a new field in the API response does not break the +# golden. +schema_fields() { + jq '{full_name, schema_id} | with_entries(select(.value != null))' +} +volume_fields() { + jq '{full_name, volume_id} | with_entries(select(.value != null))' +} diff --git a/acceptance/bundle/resources/volumes/foreign_at_recorded_name/databricks-moved.yml.tmpl b/acceptance/bundle/resources/volumes/foreign_at_recorded_name/databricks-moved.yml.tmpl new file mode 100644 index 00000000000..d9526ac454c --- /dev/null +++ b/acceptance/bundle/resources/volumes/foreign_at_recorded_name/databricks-moved.yml.tmpl @@ -0,0 +1,9 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +resources: + volumes: + volume1: + catalog_name: main + schema_name: test-schema-$UNIQUE_NAME + name: myvolume-moved diff --git a/acceptance/bundle/resources/volumes/foreign_at_recorded_name/databricks.yml.tmpl b/acceptance/bundle/resources/volumes/foreign_at_recorded_name/databricks.yml.tmpl new file mode 100644 index 00000000000..1c96e8b4c23 --- /dev/null +++ b/acceptance/bundle/resources/volumes/foreign_at_recorded_name/databricks.yml.tmpl @@ -0,0 +1,9 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +resources: + volumes: + volume1: + catalog_name: main + schema_name: test-schema-$UNIQUE_NAME + name: myvolume diff --git a/acceptance/bundle/resources/volumes/foreign_at_recorded_name/out.test.toml b/acceptance/bundle/resources/volumes/foreign_at_recorded_name/out.test.toml new file mode 100644 index 00000000000..0f167effef1 --- /dev/null +++ b/acceptance/bundle/resources/volumes/foreign_at_recorded_name/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/volumes/foreign_at_recorded_name/output.txt b/acceptance/bundle/resources/volumes/foreign_at_recorded_name/output.txt new file mode 100644 index 00000000000..9d28edb22bd --- /dev/null +++ b/acceptance/bundle/resources/volumes/foreign_at_recorded_name/output.txt @@ -0,0 +1,111 @@ + +=== Deploy a volume + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Created volumes.volume1 +Files: 4 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +=== Out of band, rename the volume away, and create another one under its name + +>>> [CLI] volumes update main.test-schema-[UNIQUE_NAME].myvolume --new-name myvolume-moved +{ + "full_name": "main.test-schema-[UNIQUE_NAME].myvolume-moved", + "volume_id": "[VOLUME_ID]" +} + +=== The other volume has another volume_id, so the plan does not take it for the bundle's: it plans a create + +>>> [CLI] bundle plan +Warning: resources.volumes.volume1: id="main.test-schema-[UNIQUE_NAME].myvolume" holds another object: its volume_id is "[FOREIGN_VOLUME_ID]", not "[VOLUME_ID]" as recorded, so this bundle does not take it for its own. If the bundle's was renamed outside the bundle, set its name in the config to the new one. If this object is the bundle's (deleted and created again outside the bundle), run 'bundle deployment unbind' and then 'bundle deployment bind' to manage it again. + +create volumes.volume1 + +Plan: 1 to add, 0 to change, 0 to delete, 0 unchanged + +=== Point the config at the bundle's renamed volume: the plan finds it there by its volume_id + +>>> [CLI] bundle plan --output json +{ + "id": "main.test-schema-[UNIQUE_NAME].myvolume-moved", + "action": "update_id", + "state_only": true, + "new_state": { + "value": { + "catalog_name": "main", + "name": "myvolume-moved", + "schema_name": "test-schema-[UNIQUE_NAME]", + "volume_type": "MANAGED" + } + }, + "changes": { + "name": { + "action": "skip", + "reason": "remote_already_set", + "old": "myvolume", + "new": "myvolume-moved", + "remote": "myvolume-moved" + }, + "volume_id": { + "action": "skip", + "reason": "internal_id", + "old": "[VOLUME_ID]", + "remote": "[VOLUME_ID]" + } + } +} + +=== Deploy takes the renamed volume for the bundle's, and sends nothing to the other one + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Files: 3 uploaded, 0 deleted +Resources: 0 created, 0 changed, 0 deleted, 1 unchanged + +>>> print_requests.py //unity-catalog + +>>> [CLI] volumes read main.test-schema-[UNIQUE_NAME].myvolume-moved +{ + "full_name": "main.test-schema-[UNIQUE_NAME].myvolume-moved", + "volume_id": "[VOLUME_ID]" +} + +>>> [CLI] volumes read main.test-schema-[UNIQUE_NAME].myvolume +{ + "full_name": "main.test-schema-[UNIQUE_NAME].myvolume", + "volume_id": "[FOREIGN_VOLUME_ID]" +} + +=== Destroy deletes the bundle's volume at its new name, not the other one + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.volumes.volume1 + +This action will result in the deletion of the following volumes. +For managed volumes, the files stored in the volume are also deleted from your +cloud tenant within 30 days. For external volumes, the metadata about the volume +is removed from the catalog, but the underlying files are not deleted: + delete resources.volumes.volume1 + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default + +Destroy: 1 deleted + +>>> print_requests.py //unity-catalog +{ + "method": "DELETE", + "path": "/api/2.1/unity-catalog/volumes/main.test-schema-[UNIQUE_NAME].myvolume-moved" +} + +>>> musterr [CLI] volumes read main.test-schema-[UNIQUE_NAME].myvolume-moved +Error: Volume 'main.test-schema-[UNIQUE_NAME].myvolume-moved' does not exist. + +=== The other volume is left alone + +>>> [CLI] volumes read main.test-schema-[UNIQUE_NAME].myvolume +{ + "full_name": "main.test-schema-[UNIQUE_NAME].myvolume", + "volume_id": "[FOREIGN_VOLUME_ID]" +} diff --git a/acceptance/bundle/resources/volumes/foreign_at_recorded_name/script b/acceptance/bundle/resources/volumes/foreign_at_recorded_name/script new file mode 100644 index 00000000000..f061dbed48a --- /dev/null +++ b/acceptance/bundle/resources/volumes/foreign_at_recorded_name/script @@ -0,0 +1,45 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +# The schema is not in the bundle, so destroy deletes the volume itself rather than its schema. +SCHEMA="main.test-schema-${UNIQUE_NAME}" + +cleanup() { + $CLI schemas delete "$SCHEMA" --force > LOG.cleanup 2>&1 || true + + # Consume the destroy's requests so none are left recorded. + print_requests.py //unity-catalog &> LOG.destroy_requests +} +trap cleanup EXIT + +$CLI schemas create "test-schema-${UNIQUE_NAME}" main > LOG.create + +title "Deploy a volume" +trace $CLI bundle deploy +print_requests.py //unity-catalog &> LOG.deploy_requests +add_repl "$($CLI volumes read "$SCHEMA.myvolume" | jq -r .volume_id)" VOLUME_ID + +title "Out of band, rename the volume away, and create another one under its name" +trace $CLI volumes update "$SCHEMA.myvolume" --new-name myvolume-moved | volume_fields +add_repl "$($CLI volumes create main "test-schema-${UNIQUE_NAME}" myvolume MANAGED | jq -r .volume_id)" FOREIGN_VOLUME_ID +print_requests.py //unity-catalog &> LOG.oob_requests + +title "The other volume has another volume_id, so the plan does not take it for the bundle's: it plans a create" +trace $CLI bundle plan + +title "Point the config at the bundle's renamed volume: the plan finds it there by its volume_id" +envsubst < databricks-moved.yml.tmpl > databricks.yml +trace $CLI bundle plan --output json | plan_filter.py resources.volumes.volume1 | normalize_uc_payload.py storage_location + +title "Deploy takes the renamed volume for the bundle's, and sends nothing to the other one" +trace $CLI bundle deploy +trace print_requests.py //unity-catalog +trace $CLI volumes read "$SCHEMA.myvolume-moved" | volume_fields +trace $CLI volumes read "$SCHEMA.myvolume" | volume_fields + +title "Destroy deletes the bundle's volume at its new name, not the other one" +trace $CLI bundle destroy --auto-approve +trace print_requests.py //unity-catalog +trace musterr $CLI volumes read "$SCHEMA.myvolume-moved" + +title "The other volume is left alone" +trace $CLI volumes read "$SCHEMA.myvolume" | volume_fields diff --git a/acceptance/bundle/resources/volumes/foreign_at_recorded_name/test.toml b/acceptance/bundle/resources/volumes/foreign_at_recorded_name/test.toml new file mode 100644 index 00000000000..4272a80cf61 --- /dev/null +++ b/acceptance/bundle/resources/volumes/foreign_at_recorded_name/test.toml @@ -0,0 +1,7 @@ +Cloud = true + +Ignore = [ + ".databricks", + ".gitignore", + "databricks.yml", +] diff --git a/bundle/deployplan/action.go b/bundle/deployplan/action.go index 698c11e56b1..f64ca6d1f7c 100644 --- a/bundle/deployplan/action.go +++ b/bundle/deployplan/action.go @@ -10,7 +10,8 @@ type Action struct { ResourceKey string ActionType ActionType // Gone mirrors PlanEntry.Gone: the delete is a state-only cleanup because the - // resource no longer exists remotely (confirmed by a read, or an empty-ID state entry). + // resource no longer exists remotely (confirmed by a read, another object at its ID, + // or an empty-ID state entry). Gone bool // StateOnly mirrors PlanEntry.StateOnly: applying the action only changes the state // (a delete of a resource without DoDelete, or a re-key). diff --git a/bundle/deployplan/plan.go b/bundle/deployplan/plan.go index 6fcaa333e08..07113d1d11c 100644 --- a/bundle/deployplan/plan.go +++ b/bundle/deployplan/plan.go @@ -131,8 +131,9 @@ type PlanEntry struct { DependsOn []DependsOnEntry `json:"depends_on,omitempty"` Action ActionType `json:"action,omitempty"` // Gone is set on Delete entries when the resource no longer exists remotely: planning - // confirmed it with a read, or the state entry has an empty ID (left by a recreate in - // an older CLI whose create step failed after the delete). Applying such an entry only + // confirmed it with a read, or found another object at its ID (an internal ID that is + // not the recorded one), or the state entry has an empty ID (left by a recreate in an + // older CLI whose create step failed after the delete). Applying such an entry only // removes it from the state, without calling the delete API, and approval prompts do // not list it as a deletion. Gone bool `json:"gone,omitempty"` diff --git a/bundle/direct/bundle_plan.go b/bundle/direct/bundle_plan.go index 9a3b20cebb3..99037e74b53 100644 --- a/bundle/direct/bundle_plan.go +++ b/bundle/direct/bundle_plan.go @@ -17,6 +17,7 @@ import ( "github.com/databricks/cli/bundle/direct/dresources" "github.com/databricks/cli/bundle/direct/dstate" "github.com/databricks/cli/bundle/terraform_dabs_map" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/dyn/dynvar" "github.com/databricks/cli/libs/log" @@ -260,6 +261,20 @@ func (b *DeploymentBundle) CalculatePlan(ctx context.Context, client *databricks // DELETING) that a GET still returns but a second delete would reject. // Treat it as gone: apply cleans up state without re-issuing the delete. entry.Gone = true + } else { + // Someone else's resource under the name ours had is never deleted: no delete is + // sent for it, and only the state entry is dropped. + message, err := b.otherObjectAtRecordedID(resourceKey, adapter, id, remoteState) + if err != nil { + logdiag.LogError(ctx, fmt.Errorf("%s: %w", errorPrefix, err)) + return false + } + if message != "" { + logdiag.LogDiag(ctx, diag.Warningf("%s: %s, so no delete is sent for it, and its entry is dropped from the deployment state. %s", + resourceKey, message, otherObjectDeleteAdvice)[0]) + entry.Gone = true + remoteState = nil + } } entry.RemoteState = remoteState @@ -349,6 +364,16 @@ func (b *DeploymentBundle) CalculatePlan(ctx context.Context, client *databricks return false } } + // Someone else's resource under the name ours had is not ours: plan as if ours were not + // there, so the plan neither updates nor later deletes it. + otherID, err := otherInternalID(adapter, savedState, remoteState) + if err != nil { + logdiag.LogError(ctx, fmt.Errorf("%s: %w", errorPrefix, err)) + return false + } + if otherID != "" { + remoteState = nil + } if remoteState == nil { entry.ID, remoteState, err = findMoved(ctx, adapter, sv, dbentry.ID, savedState) if err != nil { @@ -356,6 +381,10 @@ func (b *DeploymentBundle) CalculatePlan(ctx context.Context, client *databricks return false } } + if otherID != "" && remoteState == nil { + logdiag.LogDiag(ctx, diag.Warningf("%s: %s, so this bundle does not take it for its own. %s", + resourceKey, otherObjectMessage(adapter, dbentry.ID, savedState, otherID), otherObjectDeployAdvice)[0]) + } // We have a choice whether to include remoteState or remoteStateComparable from below. // Including remoteState because in the near future remoteState is expected to become a superset struct of remoteStateComparable @@ -870,6 +899,70 @@ func isParentIDField(adapter *dresources.Adapter, path *structpath.PathNode) boo return ok } +// otherInternalID returns the internal ID of remote, read at the recorded ID, if it is another +// object than the one savedState records: someone else's, created under the name ours had after +// ours was renamed away, or ours deleted and created again outside the bundle. It is "" when the resource is ours, or when either side has no internal ID to compare. +func otherInternalID(adapter *dresources.Adapter, savedState, remote any) (string, error) { + if !adapter.HasInternalID() || remote == nil { + return "", nil + } + saved, err := adapter.InternalID(savedState) + if err != nil || saved == "" { + return "", err + } + remapped, err := adapter.RemapState(remote) + if err != nil { + return "", err + } + found, err := adapter.InternalID(remapped) + if err != nil || found == saved { + return "", err + } + return found, nil +} + +// otherObjectMessage describes the object at the recorded ID id, whose internal ID is otherID and +// not the one savedState records. Callers add the advice, because a resource deleted and created +// again out of band looks the same. +func otherObjectMessage(adapter *dresources.Adapter, id string, savedState any, otherID string) string { + saved, _ := adapter.InternalID(savedState) + return fmt.Sprintf("id=%q holds another object: its %s is %q, not %q as recorded", + id, adapter.ResourceConfig().InternalIDField, otherID, saved) +} + +// otherObjectDeployAdvice follows otherObjectMessage for a resource in the config. The bundle's own +// may still exist under another name (renamed out of band), which findMoved takes once the config +// names it. Bind needs a free state entry, hence unbind first. +const otherObjectDeployAdvice = "If the bundle's was renamed outside the bundle, set its name in the config to the new one. If this object is the bundle's (deleted and created again outside the bundle), run 'bundle deployment unbind' and then 'bundle deployment bind' to manage it again." + +// otherObjectDeleteAdvice follows otherObjectMessage for a resource being deleted: its state entry +// is dropped, and it may no longer be in the config, so binding it is not an option. The bundle's +// own, if renamed outside the bundle, is not looked for, so the user has to delete it. +const otherObjectDeleteAdvice = "If the bundle's was renamed outside the bundle, it is left in place under its new name: delete it outside the bundle. If this object is the bundle's (deleted and created again outside the bundle), delete it outside the bundle." + +// otherObjectAtRecordedID returns, for a resource to be deleted, what otherObjectMessage says when +// remote, read at its recorded ID id, is another object than the one the state records; "" when it +// is ours, or when there is no internal ID to tell (a state entry with only the ID). The bundle's +// own is not looked for: a renamed one is left behind, as before. +func (b *DeploymentBundle) otherObjectAtRecordedID(resourceKey string, adapter *dresources.Adapter, id string, remote any) (string, error) { + if !adapter.HasInternalID() { + return "", nil + } + dbentry, _ := b.StateDB.GetResourceEntry(resourceKey) + if len(dbentry.State) == 0 { + return "", nil + } + savedState, err := parseState(adapter.StateType(), dbentry.State) + if err != nil { + return "", fmt.Errorf("interpreting state: %w", err) + } + otherID, err := otherInternalID(adapter, savedState, remote) + if err != nil || otherID == "" { + return "", err + } + return otherObjectMessage(adapter, id, savedState, otherID), nil +} + // recordRefTypes records, for each pure-reference field of resourceKey, the type of the resource it // references, before resolveReferences drops the references (see addParentMoves). func (b *DeploymentBundle) recordRefTypes(resourceKey string) error { diff --git a/bundle/direct/bundle_plan_test.go b/bundle/direct/bundle_plan_test.go index 9c5d208d159..02fbf8ffe48 100644 --- a/bundle/direct/bundle_plan_test.go +++ b/bundle/direct/bundle_plan_test.go @@ -14,6 +14,7 @@ import ( "github.com/databricks/cli/libs/structs/structdiff" "github.com/databricks/cli/libs/structs/structpath" "github.com/databricks/cli/libs/structs/structvar" + "github.com/databricks/databricks-sdk-go/service/catalog" "github.com/databricks/databricks-sdk-go/service/compute" "github.com/databricks/databricks-sdk-go/service/jobs" "github.com/databricks/databricks-sdk-go/service/pipelines" @@ -991,3 +992,63 @@ func TestAddParentMoves(t *testing.T) { }) } } + +func TestOtherInternalID(t *testing.T) { + adapters, err := dresources.InitAll(nil) + require.NoError(t, err) + adapter := adapters["schemas"] + + for name, tt := range map[string]struct { + saved, remote, want string + }{ + "same": {saved: "uuid-1", remote: "uuid-1", want: ""}, + "different": {saved: "uuid-1", remote: "uuid-2", want: "uuid-2"}, + "not recorded": {saved: "", remote: "uuid-2", want: ""}, + "not in remote": {saved: "uuid-1", remote: "", want: ""}, + "neither has internal": {saved: "", remote: "", want: ""}, + } { + t.Run(name, func(t *testing.T) { + saved := &dresources.SchemaState{SchemaId: tt.saved} + remote := &catalog.SchemaInfo{SchemaId: tt.remote} + got, err := otherInternalID(adapter, saved, remote) + require.NoError(t, err) + assert.Equal(t, tt.want, got) + }) + } + + got, err := otherInternalID(adapter, &dresources.SchemaState{SchemaId: "uuid-1"}, nil) + require.NoError(t, err) + assert.Empty(t, got) +} + +func TestOtherObjectAtRecordedID(t *testing.T) { + const key = "resources.schemas.schema1" + adapters, err := dresources.InitAll(nil) + require.NoError(t, err) + remote := &catalog.SchemaInfo{FullName: "main.s1", SchemaId: "uuid-1"} + + for name, tc := range map[string]struct { + state []byte + other bool + }{ + // The deployment metadata service can hold an entry with only an ID. + "id-only entry": {state: nil}, + "same internal id": {state: []byte(`{"catalog_name": "main", "name": "s1", "schema_id": "uuid-1"}`)}, + "internal id unset": {state: []byte(`{"catalog_name": "main", "name": "s1"}`)}, + "another internal id": {state: []byte(`{"catalog_name": "main", "name": "s1", "schema_id": "uuid-0"}`), other: true}, + } { + t.Run(name, func(t *testing.T) { + b := &DeploymentBundle{Adapters: adapters} + b.StateDB.OpenWithData("state.json", dstate.Database{State: map[string]dstate.ResourceEntry{ + key: {ID: "main.s1", State: tc.state}, + }}) + message, err := b.otherObjectAtRecordedID(key, adapters["schemas"], "main.s1", remote) + require.NoError(t, err) + if tc.other { + assert.Contains(t, message, `its schema_id is "uuid-1", not "uuid-0" as recorded`) + } else { + assert.Empty(t, message) + } + }) + } +} diff --git a/bundle/direct/dresources/README.md b/bundle/direct/dresources/README.md index 6a55f1fc109..06388f27b47 100644 --- a/bundle/direct/dresources/README.md +++ b/bundle/direct/dresources/README.md @@ -62,6 +62,8 @@ If the ID is built from the resource's own fields (a UC full name), implement `I If the backend also has its own ID that a rename keeps (a volume's `volume_id`), add it to the state type, copy it in `RemapState`, and name it in the config as `internal_id_field`. The framework records it on every save and skips its changes in the plan. When nothing is at the recorded ID, the plan reads at the ID the config gives the resource and takes what it finds only if the internal ID matches. This covers a rename done out of band, or by a deploy that stopped before re-keying the resource. +An object at the recorded ID with a different internal ID is someone else's (ours was renamed away and another created under its name, or ours was deleted and created again): the plan treats ours as not there, so it never updates or deletes the other object. A deploy then looks for ours at the ID the config gives it, as above. A delete (by destroy, or of a resource removed from config) has no config to give a new name, so it only drops the state entry and leaves the other object in place. + ## Empty states: IsEmptyState If a desired state describes no resource at all (e.g. an empty grants list), implement `IsEmptyState`. The planner omits such a node instead of planning a create, and apply drops its state entry instead of persisting one.