Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
361902a
direct: check the internal id before updating or deleting what is at …
denik Nov 25, 2026
9b84cc8
direct: fail a delete whose identity cannot be checked, warn about th…
denik Nov 25, 2026
96c69ba
direct: delete a child under its parent's found name; warn only when …
denik Nov 25, 2026
ed93200
direct: list a child of a deleted, moved parent by its ID under the p…
denik Nov 25, 2026
7e19e82
Add the PR link to the changelog fragment
denik Nov 26, 2026
a669729
direct: set every field of the schema and volume list requests (exhau…
denik Nov 26, 2026
e86d483
direct: never send an unverified child delete; find moved parents by …
denik Nov 26, 2026
16790a5
direct: order a with_parent child after its parent; follow moved pare…
denik Nov 26, 2026
9475569
direct: test fixes for the 403 search and staticcheck
denik Nov 26, 2026
c633f80
direct: re-target only unverified UC children under a moved parent
denik Nov 26, 2026
c33cefa
direct: a with_parent child keeps only its edge to its parent
denik Nov 26, 2026
ac738ad
acc: drop a trailing space in prevent_destroy_mixed_case_schema
denik Nov 26, 2026
12cd4fd
direct: limit the moved-parent lookup to UC children; order and selec…
denik Nov 26, 2026
29e7309
direct: check a with_parent entry's parent against the whole selectio…
denik Nov 26, 2026
69e2c19
direct: list every unverified child of a deleted moved parent with it
denik Nov 27, 2026
30938bb
direct: narrow to the identity check; the destroy lookup and moved pa…
denik Nov 27, 2026
d91d668
direct: separate advice for deploy and delete when another object is …
denik Nov 27, 2026
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/schema-volume-identity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Fixed the direct deployment engine taking a schema or volume that someone else created under the name of the bundle's own, after it was renamed out of band, for the bundle's: `bundle deploy` no longer updates it and `bundle destroy` no longer deletes it; destroy drops the bundle's entry from the state and warns. A schema or volume deleted and created again outside the bundle is no longer the bundle's either: deploy fails on its name and destroy leaves it, until it is bound again with `bundle deployment unbind` and `bundle deployment bind`. ([#8056](https://github.com/databricks/cli/pull/8056))
5 changes: 5 additions & 0 deletions acceptance/bin/replay_tfstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ def main():
for nf in NAME_FIELDS:
if attrs.get(nf):
name_to_attrs[str(attrs[nf])] = attrs
# 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.setdefault(str(attrs[nf]).lower(), attrs)

id_map = {}
for req in requests:
Expand All @@ -150,6 +153,8 @@ def main():
create_name = None
if isinstance(body, dict):
create_name = next((str(body[nf]) for nf in NAME_FIELDS if body.get(nf)), None)
if create_name is not None and create_name not in name_to_attrs:
create_name = create_name.lower()
if req["method"] == "POST" and create_name in name_to_attrs:
attrs = name_to_attrs[create_name]
if str(attrs["id"]) != create_name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,75 +15,84 @@ 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,
"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]"
},
"changes": {
"comment": {
"action": "update",
"old": "c1",
"new": "c1"
"plan_version": [PLAN_VERSION],
"cli_version": "[CLI_VERSION]",
"lineage": "[UUID]",
"serial": 1,
"plan": {
"resources.schemas.schema1": {
"action": "create",
"new_state": {
"value": {
"catalog_name": "main",
"comment": "c1",
"name": "test-schema-[UNIQUE_NAME]"
}
},
"schema_id": {
"action": "skip",
"reason": "internal_id",
"old": "[SCHEMA_ID]",
"remote": "[FOREIGN_SCHEMA_ID]"
"changes": {
"schema_id": {
"action": "skip",
"reason": "internal_id",
"old": "[SCHEMA_ID]"
}
}
}
}
}

=== Destroy deletes the other schema
=== Deploy leaves the other schema alone: the create fails on its name

>>> [CLI] bundle destroy --auto-approve
The following resources will be deleted:
delete resources.schemas.schema1
>>> 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.

This action will result in the deletion of the following UC schemas. Any underlying data may be lost:
delete resources.schemas.schema1
Error: cannot create resources.schemas.schema1: Schema 'test-schema-[UNIQUE_NAME]' already exists (400 SCHEMA_ALREADY_EXISTS)

All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default
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

Destroy: 1 deleted
Files: 2 uploaded, 0 deleted

>>> print_requests.py //unity-catalog
{
"method": "DELETE",
"path": "/api/2.1/unity-catalog/schemas/main.test-schema-[UNIQUE_NAME]",
"q": {
"force": "true"
"method": "POST",
"path": "/api/2.1/unity-catalog/schemas",
"body": {
"catalog_name": "main",
"comment": "c1",
"name": "test-schema-[UNIQUE_NAME]"
}
}

>>> musterr [CLI] schemas get main.test-schema-[UNIQUE_NAME]
Error: Schema 'main.test-schema-[UNIQUE_NAME]' does not exist.
=== Destroy does not delete the other schema: it only drops the bundle's 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 resources.schemas.schema1 is dropped from the deployment state. If it 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

=== The bundle's own schema is left behind
>>> 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]"
}

=== 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]"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ 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
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

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 "Destroy deletes the other schema"
title "Destroy does not delete the other schema: it only drops the bundle's from the state"
trace $CLI bundle destroy --auto-approve
trace print_requests.py //unity-catalog
trace musterr $CLI schemas get "$SCHEMA"
trace $CLI schemas get "$MOVED_SCHEMA" | schema_fields

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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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."
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 = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bundle:
name: test-bundle-$UNIQUE_NAME

resources:
schemas:
schema1:
catalog_name: main
name: test-schema-$UNIQUE_NAME
comment: c1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = true
EnvMatrix.DMS = ["", "true"]
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
envsubst < databricks.yml.tmpl > databricks.yml

SCHEMA="main.test-schema-${UNIQUE_NAME}"

cleanup() {
trace $CLI bundle destroy --auto-approve
errcode $CLI schemas delete "$SCHEMA" --force > LOG.cleanup 2>&1

# 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Cloud = true

Ignore = [
".databricks",
".gitignore",
"databricks.yml",
]
9 changes: 9 additions & 0 deletions acceptance/bundle/resources/script.prepare
Original file line number Diff line number Diff line change
@@ -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))'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bundle:
name: test-bundle-$UNIQUE_NAME

resources:
volumes:
volume1:
catalog_name: main
schema_name: test-schema-$UNIQUE_NAME
name: myvolume
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = true
EnvMatrix.DMS = ["", "true"]
Loading
Loading