From 80f624e91a51d1700c3453ddbd94f25f9374d459 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Thu, 5 Nov 2026 14:59:32 +0100 Subject: [PATCH 01/44] Rename registered models in place and follow parent renames A registered model's name is now an updatable ID field: a rename sends new_name and keeps the model's versions, instead of deleting and recreating it. A model inside a renamed catalog or schema is re-keyed without a request, like volumes; recreating it failed with RESOURCE_ALREADY_EXISTS. Co-authored-by: Isaac --- .../bundles/registered-model-rename.md | 1 + .../auto/registered-model-rename/script | 10 +- .../migrate/auto/volume-type-change/script | 2 +- .../resources/registered_models/basic/script | 2 +- .../rename/databricks.yml.tmpl | 16 + .../registered_models/rename/out.test.toml | 2 + .../registered_models/rename/output.txt | 467 ++++++++++++++++++ .../resources/registered_models/rename/script | 44 ++ .../registered_models/rename/test.toml | 7 + bundle/direct/bundle_plan_test.go | 4 +- .../dresources/configs/registered_models.yml | 7 +- bundle/direct/dresources/registered_model.go | 72 ++- 12 files changed, 602 insertions(+), 32 deletions(-) create mode 100644 .nextchanges/bundles/registered-model-rename.md create mode 100644 acceptance/bundle/resources/registered_models/rename/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/registered_models/rename/out.test.toml create mode 100644 acceptance/bundle/resources/registered_models/rename/output.txt create mode 100644 acceptance/bundle/resources/registered_models/rename/script create mode 100644 acceptance/bundle/resources/registered_models/rename/test.toml diff --git a/.nextchanges/bundles/registered-model-rename.md b/.nextchanges/bundles/registered-model-rename.md new file mode 100644 index 00000000000..80a5bc86d1d --- /dev/null +++ b/.nextchanges/bundles/registered-model-rename.md @@ -0,0 +1 @@ +* Rename a registered model in place when its `name` changes, keeping its versions, instead of deleting and recreating it. Registered models inside a renamed catalog or schema now follow it to the new name; recreating them failed because they already exist there. diff --git a/acceptance/bundle/migrate/auto/registered-model-rename/script b/acceptance/bundle/migrate/auto/registered-model-rename/script index 0b81939d6d4..94ffd9d6a25 100644 --- a/acceptance/bundle/migrate/auto/registered-model-rename/script +++ b/acceptance/bundle/migrate/auto/registered-model-rename/script @@ -10,12 +10,10 @@ title "Replay the prior terraform deployment (captured from a real terraform run trace replay_tfstate.py terraform-requests.json terraform.tfstate rm -f "$OUT_REQUESTS" -title "Rename the model (an immutable id field) and deploy on direct" -# name is a provided id field on registered models, so a rename recreates. reconcileIDFields -# seeds the deployed name into the converted state, so the migration's plan sees a real -# recreate. Unlike schemas/volumes, registered models are not in the destructive-approval -# group (a model recreate loses no data), so the deploy is approved without --auto-approve: -# the migration commits and the recreate applies on direct. +title "Rename the model (an updatable id field) and deploy on direct" +# name is an updatable id field: the model is renamed in place (UpdateWithID), keeping its +# versions. reconcileIDFields seeds the deployed name into the converted state, so the +# migration's plan sees a rename rather than snapshotting the new name as already applied. update_file.py databricks.yml "themodel-$UNIQUE_NAME" "themodel-$UNIQUE_NAME-renamed" trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy trace print_migration_telemetry diff --git a/acceptance/bundle/migrate/auto/volume-type-change/script b/acceptance/bundle/migrate/auto/volume-type-change/script index ea5ebdb1499..922c77c7b0c 100644 --- a/acceptance/bundle/migrate/auto/volume-type-change/script +++ b/acceptance/bundle/migrate/auto/volume-type-change/script @@ -2,7 +2,7 @@ export DATABRICKS_BUNDLE_ENGINE= # Testserver-only: changing volume_type to EXTERNAL needs a storage_location backed by a # registered external location on a real workspace, so this is not Cloud-enabled. The -# recreate class it covers is verified on cloud by schema-catalog-change / registered-model-rename. +# recreate class it covers is verified on cloud by schema-catalog-change / registered-model-catalog-change. # volume_type is both a provided id field and a recreate_on_changes field. reconcileIDFields # records the deployed value, so the migration's plan sees a real change and recreates. Volumes diff --git a/acceptance/bundle/resources/registered_models/basic/script b/acceptance/bundle/resources/registered_models/basic/script index 61dff74182c..91b57c1e80a 100644 --- a/acceptance/bundle/resources/registered_models/basic/script +++ b/acceptance/bundle/resources/registered_models/basic/script @@ -36,7 +36,7 @@ deploy_registered_model export NAME="my-registered-model-updated-$UNIQUE_NAME" envsubst < databricks.yml.tmpl > databricks.yml -title "update the name, this should recreate" +title "update the name, this renames the model in place" deploy_registered_model title "update the catalog name, this should recreate" diff --git a/acceptance/bundle/resources/registered_models/rename/databricks.yml.tmpl b/acceptance/bundle/resources/registered_models/rename/databricks.yml.tmpl new file mode 100644 index 00000000000..957167b6ad5 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename/databricks.yml.tmpl @@ -0,0 +1,16 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +resources: + catalogs: + catalog1: + name: test_catalog_$UNIQUE_NAME + schemas: + schema1: + catalog_name: ${resources.catalogs.catalog1.name} + name: myschema + registered_models: + model1: + catalog_name: ${resources.catalogs.catalog1.name} + schema_name: ${resources.schemas.schema1.name} + name: mymodel diff --git a/acceptance/bundle/resources/registered_models/rename/out.test.toml b/acceptance/bundle/resources/registered_models/rename/out.test.toml new file mode 100644 index 00000000000..0f167effef1 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/registered_models/rename/output.txt b/acceptance/bundle/resources/registered_models/rename/output.txt new file mode 100644 index 00000000000..f5d604df265 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename/output.txt @@ -0,0 +1,467 @@ + +=== Deploy a catalog with a schema and a registered model in it +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Created catalogs.catalog1 +Created registered_models.model1 +Created schemas.schema1 +Files: 2 uploaded, 0 deleted +Resources: 3 created, 0 changed, 0 deleted, 0 unchanged + +>>> print_requests.py //unity-catalog +{ + "method": "POST", + "path": "/api/2.1/unity-catalog/catalogs", + "body": { + "name": "test_catalog_[UNIQUE_NAME]" + } +} +{ + "method": "POST", + "path": "/api/2.1/unity-catalog/schemas", + "body": { + "catalog_name": "test_catalog_[UNIQUE_NAME]", + "name": "myschema" + } +} +{ + "method": "POST", + "path": "/api/2.1/unity-catalog/models", + "body": { + "catalog_name": "test_catalog_[UNIQUE_NAME]", + "name": "mymodel", + "schema_name": "myschema" + } +} + +=== Rename the model: it is renamed in place, keeping its versions +>>> update_file.py databricks.yml name: mymodel name: mymodel2 + +>>> [CLI] bundle plan --output json +{ + "resources.catalogs.catalog1": { + "action": "skip", + "remote_state": { + "catalog_type": "MANAGED_CATALOG", + "created_by": "[USERNAME]", + "full_name": "test_catalog_[UNIQUE_NAME]", + "name": "test_catalog_[UNIQUE_NAME]", + "owner": "[USERNAME]" + } + }, + "resources.registered_models.model1": { + "depends_on": [ + { + "node": "resources.catalogs.catalog1", + "label": "${resources.catalogs.catalog1.name}" + }, + { + "node": "resources.schemas.schema1", + "label": "${resources.schemas.schema1.name}" + } + ], + "action": "update_id", + "new_state": { + "value": { + "catalog_name": "test_catalog_[UNIQUE_NAME]", + "name": "mymodel2", + "schema_name": "myschema" + } + }, + "remote_state": { + "catalog_name": "test_catalog_[UNIQUE_NAME]", + "created_by": "[USERNAME]", + "full_name": "test_catalog_[UNIQUE_NAME].myschema.mymodel", + "name": "mymodel", + "owner": "[USERNAME]", + "schema_name": "myschema" + }, + "changes": { + "created_by": { + "action": "skip", + "reason": "output_only", + "remote": "[USERNAME]" + }, + "full_name": { + "action": "skip", + "reason": "backend_default", + "remote": "test_catalog_[UNIQUE_NAME].myschema.mymodel" + }, + "name": { + "action": "update_id", + "reason": "id_changes", + "old": "mymodel", + "new": "mymodel2", + "remote": "mymodel" + }, + "owner": { + "action": "skip", + "reason": "backend_default", + "remote": "[USERNAME]" + } + } + }, + "resources.schemas.schema1": { + "depends_on": [ + { + "node": "resources.catalogs.catalog1", + "label": "${resources.catalogs.catalog1.name}" + } + ], + "action": "skip", + "remote_state": { + "catalog_name": "test_catalog_[UNIQUE_NAME]", + "catalog_type": "MANAGED_CATALOG", + "created_by": "[USERNAME]", + "full_name": "test_catalog_[UNIQUE_NAME].myschema", + "name": "myschema", + "owner": "[USERNAME]", + "schema_id": "[UUID]" + } + } +} + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Updated registered_models.model1 +Files: 1 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 2 unchanged + +>>> print_requests.py //unity-catalog +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/models/test_catalog_[UNIQUE_NAME].myschema.mymodel", + "body": { + "catalog_name": "test_catalog_[UNIQUE_NAME]", + "comment": "", + "new_name": "mymodel2", + "schema_name": "myschema" + } +} + +>>> [CLI] registered-models get test_catalog_[UNIQUE_NAME].myschema.mymodel2 +{ + "full_name": "test_catalog_[UNIQUE_NAME].myschema.mymodel2", + "created_at": [MODEL_CREATED_AT] +} + +=== Rename the schema: UC moves the model with it, so the model is re-keyed without a request +>>> update_file.py databricks.yml name: myschema name: myschema2 + +>>> [CLI] bundle plan --output json +{ + "resources.catalogs.catalog1": { + "action": "skip", + "remote_state": { + "catalog_type": "MANAGED_CATALOG", + "created_by": "[USERNAME]", + "full_name": "test_catalog_[UNIQUE_NAME]", + "name": "test_catalog_[UNIQUE_NAME]", + "owner": "[USERNAME]" + } + }, + "resources.registered_models.model1": { + "depends_on": [ + { + "node": "resources.catalogs.catalog1", + "label": "${resources.catalogs.catalog1.name}" + }, + { + "node": "resources.schemas.schema1", + "label": "${resources.schemas.schema1.name}" + } + ], + "action": "update_id", + "new_state": { + "value": { + "catalog_name": "test_catalog_[UNIQUE_NAME]", + "name": "mymodel2", + "schema_name": "myschema2" + } + }, + "remote_state": { + "catalog_name": "test_catalog_[UNIQUE_NAME]", + "comment": "", + "created_by": "[USERNAME]", + "full_name": "test_catalog_[UNIQUE_NAME].myschema.mymodel2", + "name": "mymodel2", + "owner": "[USERNAME]", + "schema_name": "myschema" + }, + "changes": { + "comment": { + "action": "skip", + "reason": "empty", + "remote": "" + }, + "created_by": { + "action": "skip", + "reason": "output_only", + "remote": "[USERNAME]" + }, + "full_name": { + "action": "skip", + "reason": "backend_default", + "remote": "test_catalog_[UNIQUE_NAME].myschema.mymodel2" + }, + "owner": { + "action": "skip", + "reason": "backend_default", + "remote": "[USERNAME]" + }, + "schema_name": { + "action": "update_id", + "reason": "parent_renamed", + "old": "myschema", + "new": "myschema2", + "remote": "myschema" + } + } + }, + "resources.schemas.schema1": { + "depends_on": [ + { + "node": "resources.catalogs.catalog1", + "label": "${resources.catalogs.catalog1.name}" + } + ], + "action": "update_id", + "new_state": { + "value": { + "catalog_name": "test_catalog_[UNIQUE_NAME]", + "name": "myschema2" + } + }, + "remote_state": { + "catalog_name": "test_catalog_[UNIQUE_NAME]", + "catalog_type": "MANAGED_CATALOG", + "created_by": "[USERNAME]", + "full_name": "test_catalog_[UNIQUE_NAME].myschema", + "name": "myschema", + "owner": "[USERNAME]", + "schema_id": "[UUID]" + }, + "changes": { + "name": { + "action": "update_id", + "reason": "id_changes", + "old": "myschema", + "new": "myschema2", + "remote": "myschema" + } + } + } +} + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Updated registered_models.model1 +Updated schemas.schema1 +Files: 1 uploaded, 0 deleted +Resources: 0 created, 2 changed, 0 deleted, 1 unchanged + +>>> print_requests.py //unity-catalog +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/schemas/test_catalog_[UNIQUE_NAME].myschema", + "body": { + "comment": "", + "custom_max_retention_hours": 0, + "new_name": "myschema2" + } +} + +>>> [CLI] registered-models get test_catalog_[UNIQUE_NAME].myschema2.mymodel2 +{ + "full_name": "test_catalog_[UNIQUE_NAME].myschema2.mymodel2", + "created_at": [MODEL_CREATED_AT] +} + +=== Rename the catalog: the model is re-keyed again +>>> update_file.py databricks.yml test_catalog_ test_catalog_renamed_ + +>>> [CLI] bundle plan --output json +{ + "resources.catalogs.catalog1": { + "action": "update_id", + "new_state": { + "value": { + "name": "test_catalog_renamed_[UNIQUE_NAME]" + } + }, + "remote_state": { + "catalog_type": "MANAGED_CATALOG", + "created_by": "[USERNAME]", + "full_name": "test_catalog_[UNIQUE_NAME]", + "name": "test_catalog_[UNIQUE_NAME]", + "owner": "[USERNAME]" + }, + "changes": { + "name": { + "action": "update_id", + "reason": "id_changes", + "old": "test_catalog_[UNIQUE_NAME]", + "new": "test_catalog_renamed_[UNIQUE_NAME]", + "remote": "test_catalog_[UNIQUE_NAME]" + } + } + }, + "resources.registered_models.model1": { + "depends_on": [ + { + "node": "resources.catalogs.catalog1", + "label": "${resources.catalogs.catalog1.name}" + }, + { + "node": "resources.schemas.schema1", + "label": "${resources.schemas.schema1.name}" + } + ], + "action": "update_id", + "new_state": { + "value": { + "catalog_name": "test_catalog_renamed_[UNIQUE_NAME]", + "name": "mymodel2", + "schema_name": "myschema2" + } + }, + "remote_state": { + "catalog_name": "test_catalog_[UNIQUE_NAME]", + "comment": "", + "created_by": "[USERNAME]", + "full_name": "test_catalog_[UNIQUE_NAME].myschema2.mymodel2", + "name": "mymodel2", + "owner": "[USERNAME]", + "schema_name": "myschema2" + }, + "changes": { + "catalog_name": { + "action": "update_id", + "reason": "parent_renamed", + "old": "test_catalog_[UNIQUE_NAME]", + "new": "test_catalog_renamed_[UNIQUE_NAME]", + "remote": "test_catalog_[UNIQUE_NAME]" + }, + "comment": { + "action": "skip", + "reason": "empty", + "remote": "" + }, + "created_by": { + "action": "skip", + "reason": "output_only", + "remote": "[USERNAME]" + }, + "full_name": { + "action": "skip", + "reason": "backend_default", + "remote": "test_catalog_[UNIQUE_NAME].myschema2.mymodel2" + }, + "owner": { + "action": "skip", + "reason": "backend_default", + "remote": "[USERNAME]" + } + } + }, + "resources.schemas.schema1": { + "depends_on": [ + { + "node": "resources.catalogs.catalog1", + "label": "${resources.catalogs.catalog1.name}" + } + ], + "action": "update_id", + "new_state": { + "value": { + "catalog_name": "test_catalog_renamed_[UNIQUE_NAME]", + "name": "myschema2" + } + }, + "remote_state": { + "catalog_name": "test_catalog_[UNIQUE_NAME]", + "catalog_type": "MANAGED_CATALOG", + "comment": "", + "created_by": "[USERNAME]", + "custom_max_retention_hours": 0, + "full_name": "test_catalog_[UNIQUE_NAME].myschema2", + "name": "myschema2", + "owner": "[USERNAME]", + "schema_id": "[UUID]" + }, + "changes": { + "catalog_name": { + "action": "update_id", + "reason": "parent_renamed", + "old": "test_catalog_[UNIQUE_NAME]", + "new": "test_catalog_renamed_[UNIQUE_NAME]", + "remote": "test_catalog_[UNIQUE_NAME]" + }, + "comment": { + "action": "skip", + "reason": "empty", + "remote": "" + }, + "custom_max_retention_hours": { + "action": "skip", + "reason": "empty", + "remote": 0 + } + } + } +} + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Updated catalogs.catalog1 +Updated registered_models.model1 +Updated schemas.schema1 +Files: 1 uploaded, 0 deleted +Resources: 0 created, 3 changed, 0 deleted, 0 unchanged + +>>> print_requests.py //unity-catalog +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/catalogs/test_catalog_[UNIQUE_NAME]", + "body": { + "comment": "", + "custom_max_retention_hours": 0, + "new_name": "test_catalog_renamed_[UNIQUE_NAME]" + } +} + +>>> [CLI] registered-models get test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel2 +{ + "full_name": "test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel2", + "created_at": [MODEL_CREATED_AT] +} + +=== The state tracks the new paths and the plan is a no-op +>>> [CLI] bundle summary --output json +{ + "catalogs": { + "catalog1": "test_catalog_renamed_[UNIQUE_NAME]" + }, + "registered_models": { + "model1": "test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel2" + }, + "schemas": { + "schema1": "test_catalog_renamed_[UNIQUE_NAME].myschema2" + } +} + +>>> [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.catalogs.catalog1 + delete resources.registered_models.model1 + 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: 3 deleted diff --git a/acceptance/bundle/resources/registered_models/rename/script b/acceptance/bundle/resources/registered_models/rename/script new file mode 100644 index 00000000000..09f2bf95ca3 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename/script @@ -0,0 +1,44 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace $CLI bundle destroy --auto-approve + + # Consume the destroy's requests so none are left recorded. + print_requests.py //unity-catalog &> LOG.destroy_requests +} +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 browse_only effective_predictive_optimization_flag enable_predictive_optimization isolation_mode securable_type storage_location +} + +title "Deploy a catalog with a schema and a registered model in it" +trace $CLI bundle deploy +trace print_requests.py //unity-catalog +add_repl "$($CLI registered-models get "test_catalog_${UNIQUE_NAME}.myschema.mymodel" | jq -r .created_at)" MODEL_CREATED_AT + +title "Rename the model: it is renamed in place, keeping its versions" +trace update_file.py databricks.yml "name: mymodel" "name: mymodel2" +plan +trace $CLI bundle deploy +trace print_requests.py //unity-catalog +trace $CLI registered-models get "test_catalog_${UNIQUE_NAME}.myschema.mymodel2" | jq '{full_name, created_at}' + +title "Rename the schema: UC moves the model with it, so the model is re-keyed without a request" +trace update_file.py databricks.yml "name: myschema" "name: myschema2" +plan +trace $CLI bundle deploy +trace print_requests.py //unity-catalog +trace $CLI registered-models get "test_catalog_${UNIQUE_NAME}.myschema2.mymodel2" | jq '{full_name, created_at}' + +title "Rename the catalog: the model is re-keyed again" +trace update_file.py databricks.yml test_catalog_ test_catalog_renamed_ +plan +trace $CLI bundle deploy +trace print_requests.py //unity-catalog +trace $CLI registered-models get "test_catalog_renamed_${UNIQUE_NAME}.myschema2.mymodel2" | jq '{full_name, created_at}' + +title "The state tracks the new paths and the plan is a no-op" +trace $CLI bundle summary --output json | jq '.resources | map_values(map_values(.id))' +trace $CLI bundle plan diff --git a/acceptance/bundle/resources/registered_models/rename/test.toml b/acceptance/bundle/resources/registered_models/rename/test.toml new file mode 100644 index 00000000000..4272a80cf61 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename/test.toml @@ -0,0 +1,7 @@ +Cloud = true + +Ignore = [ + ".databricks", + ".gitignore", + "databricks.yml", +] diff --git a/bundle/direct/bundle_plan_test.go b/bundle/direct/bundle_plan_test.go index a632dd11f7d..947f5bee96d 100644 --- a/bundle/direct/bundle_plan_test.go +++ b/bundle/direct/bundle_plan_test.go @@ -302,8 +302,8 @@ func TestFollowsParentRename(t *testing.T) { }, { name: "resource without DoUpdateWithID is recreated", - resource: "registered_models", - field: "schema_name", + resource: "quality_monitors", + field: "table_name", old: "s_old", expectedAction: deployplan.Recreate, }, diff --git a/bundle/direct/dresources/configs/registered_models.yml b/bundle/direct/dresources/configs/registered_models.yml index 6ef0dcead00..598198e003e 100644 --- a/bundle/direct/dresources/configs/registered_models.yml +++ b/bundle/direct/dresources/configs/registered_models.yml @@ -20,10 +20,6 @@ ignore_remote_changes: - field: aliases[*].model_name reason: output_only provided_id_fields: - # The name can technically be updated without recreate. We recreate for now though - # to match TF implementation. - - field: name - reason: terraform_compat - field: catalog_name reason: id_field - field: schema_name @@ -33,6 +29,9 @@ parent_id_fields: reason: parent - field: schema_name reason: parent +updatable_id_fields: + - field: name + reason: id_changes recreate_on_changes: - field: storage_location reason: immutable diff --git a/bundle/direct/dresources/registered_model.go b/bundle/direct/dresources/registered_model.go index 4352b848fe8..3e07817abaf 100644 --- a/bundle/direct/dresources/registered_model.go +++ b/bundle/direct/dresources/registered_model.go @@ -91,9 +91,14 @@ func (r *ResourceRegisteredModel) WaitAfterCreate(ctx context.Context, id string // See schemaForceSend. Verified against a real workspace: {"comment": ""} clears it. var registeredModelForceSend = []string{"Comment"} -func (r *ResourceRegisteredModel) DoUpdate(ctx context.Context, id string, config *catalog.CreateRegisteredModelRequest, entry *PlanEntry) (*catalog.RegisteredModelInfo, error) { - updateRequest := catalog.UpdateRegisteredModelRequest{ - FullName: id, +func makeUpdateRegisteredModel(fullName, newName string, config *catalog.CreateRegisteredModelRequest) catalog.UpdateRegisteredModelRequest { + // UC rejects an update that sets both name and new_name. + name := config.Name + if newName != "" { + name = "" + } + return catalog.UpdateRegisteredModelRequest{ + FullName: fullName, Comment: config.Comment, ForceSendFields: utils.FilterFields[catalog.UpdateRegisteredModelRequest](append(slices.Clone(registeredModelForceSend), config.ForceSendFields...), "Owner", "NewName"), @@ -102,9 +107,8 @@ func (r *ResourceRegisteredModel) DoUpdate(ctx context.Context, id string, confi // change to it is silently dropped rather than applied. Owner: "", - // Name updates are not supported yet without recreating. Can be added as a follow-up. - // Note: TF also does not support changing name without a recreate so the current behavior matches TF. - NewName: "", + // Set by DoUpdateWithID when the name changes. + NewName: newName, // The update API ignores aliases; syncAliases applies them through the alias API. Aliases: nil, @@ -117,27 +121,59 @@ func (r *ResourceRegisteredModel) DoUpdate(ctx context.Context, id string, confi UpdatedBy: config.UpdatedBy, SchemaName: config.SchemaName, StorageLocation: config.StorageLocation, - Name: config.Name, + Name: name, CatalogName: config.CatalogName, } +} - response, err := r.client.RegisteredModels.Update(ctx, updateRequest) +func (r *ResourceRegisteredModel) DoUpdate(ctx context.Context, id string, config *catalog.CreateRegisteredModelRequest, entry *PlanEntry) (*catalog.RegisteredModelInfo, error) { + response, err := r.client.RegisteredModels.Update(ctx, makeUpdateRegisteredModel(id, "", config)) if err != nil { return nil, err } + return response, r.syncChangedAliases(ctx, id, config, entry) +} - if entry.Changes.HasChange(registeredModelAliasesPath) { - remote, ok := entry.RemoteState.(*catalog.RegisteredModelInfo) - if !ok { - return nil, fmt.Errorf("internal error: unexpected remote state type %T", entry.RemoteState) - } - err = r.syncAliases(ctx, id, config.Aliases, remote.Aliases) - if err != nil { - return nil, err - } +// DoUpdateWithID renames the model in place when the name changes, keeping its versions; the ID is +// the full name, so it changes too. +func (r *ResourceRegisteredModel) DoUpdateWithID(ctx context.Context, id string, config *catalog.CreateRegisteredModelRequest, entry *PlanEntry) (string, *catalog.RegisteredModelInfo, error) { + nameFromID, err := getNameFromID(id) + if err != nil { + return "", nil, err } - return response, nil + // The catalog and schema come from config: a renamed parent moves the model with it, leaving id + // stale (see followParentRenames). + parent := config.CatalogName + "." + config.SchemaName + "." + newID := parent + config.Name + + if entry.Changes.OnlyParentRenamed() { + // UC already moved the model with its parent; only the ID changes. + return newID, nil, nil + } + + newName := "" + if config.Name != nameFromID { + newName = config.Name + } + + response, err := r.client.RegisteredModels.Update(ctx, makeUpdateRegisteredModel(parent+nameFromID, newName, config)) + if err != nil { + return "", nil, err + } + return newID, response, r.syncChangedAliases(ctx, newID, config, entry) +} + +// syncChangedAliases applies the configured aliases when the plan changes them. +func (r *ResourceRegisteredModel) syncChangedAliases(ctx context.Context, fullName string, config *catalog.CreateRegisteredModelRequest, entry *PlanEntry) error { + if !entry.Changes.HasChange(registeredModelAliasesPath) { + return nil + } + remote, ok := entry.RemoteState.(*catalog.RegisteredModelInfo) + if !ok { + return fmt.Errorf("internal error: unexpected remote state type %T", entry.RemoteState) + } + return r.syncAliases(ctx, fullName, config.Aliases, remote.Aliases) } // syncAliases makes the model's aliases match desired, given the ones it has remotely. The alias API From aeb36e710916baba62b223921b373ec49d8d4969 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Thu, 5 Nov 2026 15:03:38 +0100 Subject: [PATCH 02/44] Link PR in changelog fragment Co-authored-by: Isaac --- .nextchanges/bundles/registered-model-rename.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/bundles/registered-model-rename.md b/.nextchanges/bundles/registered-model-rename.md index 80a5bc86d1d..5cf62805994 100644 --- a/.nextchanges/bundles/registered-model-rename.md +++ b/.nextchanges/bundles/registered-model-rename.md @@ -1 +1 @@ -* Rename a registered model in place when its `name` changes, keeping its versions, instead of deleting and recreating it. Registered models inside a renamed catalog or schema now follow it to the new name; recreating them failed because they already exist there. +* Rename a registered model in place when its `name` changes, keeping its versions, instead of deleting and recreating it. Registered models inside a renamed catalog or schema now follow it to the new name; recreating them failed because they already exist there. ([#7379](https://github.com/databricks/cli/pull/7379)) From 0b02037d966d92a18fd690d94b2e715ed244a44e Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Thu, 5 Nov 2026 16:30:10 +0100 Subject: [PATCH 03/44] direct: read a moved model's aliases when the plan could not After an interrupted parent rename the plan reads the model at its stale ID and has no remote state; sync aliases against the model at its new path instead. Co-authored-by: Isaac --- bundle/direct/dresources/registered_model.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bundle/direct/dresources/registered_model.go b/bundle/direct/dresources/registered_model.go index 3e07817abaf..8cad3dbf87f 100644 --- a/bundle/direct/dresources/registered_model.go +++ b/bundle/direct/dresources/registered_model.go @@ -169,6 +169,14 @@ func (r *ResourceRegisteredModel) syncChangedAliases(ctx context.Context, fullNa if !entry.Changes.HasChange(registeredModelAliasesPath) { return nil } + if entry.RemoteState == nil { + // The plan read the model at a stale ID: an interrupted deploy renamed its parent. + remote, err := r.DoRead(ctx, fullName) + if err != nil { + return err + } + return r.syncAliases(ctx, fullName, config.Aliases, remote.Aliases) + } remote, ok := entry.RemoteState.(*catalog.RegisteredModelInfo) if !ok { return fmt.Errorf("internal error: unexpected remote state type %T", entry.RemoteState) From 2eba1b4dde6b8e09e0c76fe1ee288b3323d3760e Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Fri, 6 Nov 2026 12:16:58 +0100 Subject: [PATCH 04/44] Drop the alias read for a model the plan could not read; delete models with their schema A model missing from its recorded ID is planned as a create again, so DoUpdateWithID always has the plan's remote state. A forced schema or catalog delete in the test server now also deletes the registered models in it, like UC. Co-authored-by: Isaac --- bundle/direct/dresources/registered_model.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/bundle/direct/dresources/registered_model.go b/bundle/direct/dresources/registered_model.go index 8cad3dbf87f..3e07817abaf 100644 --- a/bundle/direct/dresources/registered_model.go +++ b/bundle/direct/dresources/registered_model.go @@ -169,14 +169,6 @@ func (r *ResourceRegisteredModel) syncChangedAliases(ctx context.Context, fullNa if !entry.Changes.HasChange(registeredModelAliasesPath) { return nil } - if entry.RemoteState == nil { - // The plan read the model at a stale ID: an interrupted deploy renamed its parent. - remote, err := r.DoRead(ctx, fullName) - if err != nil { - return err - } - return r.syncAliases(ctx, fullName, config.Aliases, remote.Aliases) - } remote, ok := entry.RemoteState.(*catalog.RegisteredModelInfo) if !ok { return fmt.Errorf("internal error: unexpected remote state type %T", entry.RemoteState) From 7e88694df0482b7519ad6cc19e4abc43f3665bb7 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 9 Nov 2026 12:48:12 +0100 Subject: [PATCH 05/44] acc: show the skipped schema_id change in the model rename plans Co-authored-by: Isaac --- .../registered_models/rename/output.txt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/acceptance/bundle/resources/registered_models/rename/output.txt b/acceptance/bundle/resources/registered_models/rename/output.txt index f5d604df265..d48f0c8b937 100644 --- a/acceptance/bundle/resources/registered_models/rename/output.txt +++ b/acceptance/bundle/resources/registered_models/rename/output.txt @@ -117,6 +117,14 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged "name": "myschema", "owner": "[USERNAME]", "schema_id": "[UUID]" + }, + "changes": { + "schema_id": { + "action": "skip", + "reason": "internal_id", + "old": "[UUID]", + "remote": "[UUID]" + } } } } @@ -248,6 +256,12 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged "old": "myschema", "new": "myschema2", "remote": "myschema" + }, + "schema_id": { + "action": "skip", + "reason": "internal_id", + "old": "[UUID]", + "remote": "[UUID]" } } } @@ -406,6 +420,12 @@ Resources: 0 created, 2 changed, 0 deleted, 1 unchanged "action": "skip", "reason": "empty", "remote": 0 + }, + "schema_id": { + "action": "skip", + "reason": "internal_id", + "old": "[UUID]", + "remote": "[UUID]" } } } From 4e37f0f613b3dbacd63617d71896a3f298ee2b9f Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 9 Nov 2026 14:07:46 +0100 Subject: [PATCH 06/44] Point comment at followsParentRename Co-authored-by: Isaac --- bundle/direct/dresources/registered_model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/direct/dresources/registered_model.go b/bundle/direct/dresources/registered_model.go index 3e07817abaf..3fa4872f86d 100644 --- a/bundle/direct/dresources/registered_model.go +++ b/bundle/direct/dresources/registered_model.go @@ -143,7 +143,7 @@ func (r *ResourceRegisteredModel) DoUpdateWithID(ctx context.Context, id string, } // The catalog and schema come from config: a renamed parent moves the model with it, leaving id - // stale (see followParentRenames). + // stale (see followsParentRename). parent := config.CatalogName + "." + config.SchemaName + "." newID := parent + config.Name From d7549b2974ef6326f3300c0955e0943937e479a9 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 9 Nov 2026 15:49:04 +0100 Subject: [PATCH 07/44] direct: let the framework re-key a model that only follows its parent; test rename with a comment change Co-authored-by: Isaac --- .../rename/databricks.yml.tmpl | 1 + .../registered_models/rename/output.txt | 63 +++++++++++++------ .../resources/registered_models/rename/script | 7 +++ bundle/direct/dresources/registered_model.go | 5 -- 4 files changed, 52 insertions(+), 24 deletions(-) diff --git a/acceptance/bundle/resources/registered_models/rename/databricks.yml.tmpl b/acceptance/bundle/resources/registered_models/rename/databricks.yml.tmpl index 957167b6ad5..4b30bc96c3d 100644 --- a/acceptance/bundle/resources/registered_models/rename/databricks.yml.tmpl +++ b/acceptance/bundle/resources/registered_models/rename/databricks.yml.tmpl @@ -14,3 +14,4 @@ resources: catalog_name: ${resources.catalogs.catalog1.name} schema_name: ${resources.schemas.schema1.name} name: mymodel + comment: c1 diff --git a/acceptance/bundle/resources/registered_models/rename/output.txt b/acceptance/bundle/resources/registered_models/rename/output.txt index d48f0c8b937..a85544f2483 100644 --- a/acceptance/bundle/resources/registered_models/rename/output.txt +++ b/acceptance/bundle/resources/registered_models/rename/output.txt @@ -29,6 +29,7 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged "path": "/api/2.1/unity-catalog/models", "body": { "catalog_name": "test_catalog_[UNIQUE_NAME]", + "comment": "c1", "name": "mymodel", "schema_name": "myschema" } @@ -64,12 +65,14 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged "new_state": { "value": { "catalog_name": "test_catalog_[UNIQUE_NAME]", + "comment": "c1", "name": "mymodel2", "schema_name": "myschema" } }, "remote_state": { "catalog_name": "test_catalog_[UNIQUE_NAME]", + "comment": "c1", "created_by": "[USERNAME]", "full_name": "test_catalog_[UNIQUE_NAME].myschema.mymodel", "name": "mymodel", @@ -141,7 +144,7 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged "path": "/api/2.1/unity-catalog/models/test_catalog_[UNIQUE_NAME].myschema.mymodel", "body": { "catalog_name": "test_catalog_[UNIQUE_NAME]", - "comment": "", + "comment": "c1", "new_name": "mymodel2", "schema_name": "myschema" } @@ -180,16 +183,18 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged } ], "action": "update_id", + "state_only": true, "new_state": { "value": { "catalog_name": "test_catalog_[UNIQUE_NAME]", + "comment": "c1", "name": "mymodel2", "schema_name": "myschema2" } }, "remote_state": { "catalog_name": "test_catalog_[UNIQUE_NAME]", - "comment": "", + "comment": "c1", "created_by": "[USERNAME]", "full_name": "test_catalog_[UNIQUE_NAME].myschema.mymodel2", "name": "mymodel2", @@ -197,11 +202,6 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged "schema_name": "myschema" }, "changes": { - "comment": { - "action": "skip", - "reason": "empty", - "remote": "" - }, "created_by": { "action": "skip", "reason": "output_only", @@ -269,10 +269,9 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... -Updated registered_models.model1 Updated schemas.schema1 Files: 1 uploaded, 0 deleted -Resources: 0 created, 2 changed, 0 deleted, 1 unchanged +Resources: 0 created, 1 changed, 0 deleted, 2 unchanged >>> print_requests.py //unity-catalog { @@ -332,16 +331,18 @@ Resources: 0 created, 2 changed, 0 deleted, 1 unchanged } ], "action": "update_id", + "state_only": true, "new_state": { "value": { "catalog_name": "test_catalog_renamed_[UNIQUE_NAME]", + "comment": "c1", "name": "mymodel2", "schema_name": "myschema2" } }, "remote_state": { "catalog_name": "test_catalog_[UNIQUE_NAME]", - "comment": "", + "comment": "c1", "created_by": "[USERNAME]", "full_name": "test_catalog_[UNIQUE_NAME].myschema2.mymodel2", "name": "mymodel2", @@ -356,11 +357,6 @@ Resources: 0 created, 2 changed, 0 deleted, 1 unchanged "new": "test_catalog_renamed_[UNIQUE_NAME]", "remote": "test_catalog_[UNIQUE_NAME]" }, - "comment": { - "action": "skip", - "reason": "empty", - "remote": "" - }, "created_by": { "action": "skip", "reason": "output_only", @@ -386,6 +382,7 @@ Resources: 0 created, 2 changed, 0 deleted, 1 unchanged } ], "action": "update_id", + "state_only": true, "new_state": { "value": { "catalog_name": "test_catalog_renamed_[UNIQUE_NAME]", @@ -434,10 +431,8 @@ Resources: 0 created, 2 changed, 0 deleted, 1 unchanged >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Updated catalogs.catalog1 -Updated registered_models.model1 -Updated schemas.schema1 Files: 1 uploaded, 0 deleted -Resources: 0 created, 3 changed, 0 deleted, 0 unchanged +Resources: 0 created, 1 changed, 0 deleted, 2 unchanged >>> print_requests.py //unity-catalog { @@ -456,6 +451,36 @@ Resources: 0 created, 3 changed, 0 deleted, 0 unchanged "created_at": [MODEL_CREATED_AT] } +=== Rename the model and change its comment in one deploy: both go in one PATCH +>>> update_file.py databricks.yml name: mymodel2 name: mymodel3 + +>>> update_file.py databricks.yml comment: c1 comment: c2 + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Updated registered_models.model1 +Files: 1 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 2 unchanged + +>>> print_requests.py //unity-catalog +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/models/test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel2", + "body": { + "catalog_name": "test_catalog_renamed_[UNIQUE_NAME]", + "comment": "c2", + "new_name": "mymodel3", + "schema_name": "myschema2" + } +} + +>>> [CLI] registered-models get test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel3 +{ + "full_name": "test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel3", + "comment": "c2", + "created_at": [MODEL_CREATED_AT] +} + === The state tracks the new paths and the plan is a no-op >>> [CLI] bundle summary --output json { @@ -463,7 +488,7 @@ Resources: 0 created, 3 changed, 0 deleted, 0 unchanged "catalog1": "test_catalog_renamed_[UNIQUE_NAME]" }, "registered_models": { - "model1": "test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel2" + "model1": "test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel3" }, "schemas": { "schema1": "test_catalog_renamed_[UNIQUE_NAME].myschema2" diff --git a/acceptance/bundle/resources/registered_models/rename/script b/acceptance/bundle/resources/registered_models/rename/script index 09f2bf95ca3..5c057eb0bf5 100644 --- a/acceptance/bundle/resources/registered_models/rename/script +++ b/acceptance/bundle/resources/registered_models/rename/script @@ -39,6 +39,13 @@ trace $CLI bundle deploy trace print_requests.py //unity-catalog trace $CLI registered-models get "test_catalog_renamed_${UNIQUE_NAME}.myschema2.mymodel2" | jq '{full_name, created_at}' +title "Rename the model and change its comment in one deploy: both go in one PATCH" +trace update_file.py databricks.yml "name: mymodel2" "name: mymodel3" +trace update_file.py databricks.yml "comment: c1" "comment: c2" +trace $CLI bundle deploy +trace print_requests.py //unity-catalog +trace $CLI registered-models get "test_catalog_renamed_${UNIQUE_NAME}.myschema2.mymodel3" | jq '{full_name, comment, created_at}' + title "The state tracks the new paths and the plan is a no-op" trace $CLI bundle summary --output json | jq '.resources | map_values(map_values(.id))' trace $CLI bundle plan diff --git a/bundle/direct/dresources/registered_model.go b/bundle/direct/dresources/registered_model.go index 3fa4872f86d..e00fb4f500f 100644 --- a/bundle/direct/dresources/registered_model.go +++ b/bundle/direct/dresources/registered_model.go @@ -147,11 +147,6 @@ func (r *ResourceRegisteredModel) DoUpdateWithID(ctx context.Context, id string, parent := config.CatalogName + "." + config.SchemaName + "." newID := parent + config.Name - if entry.Changes.OnlyParentRenamed() { - // UC already moved the model with its parent; only the ID changes. - return newID, nil, nil - } - newName := "" if config.Name != nameFromID { newName = config.Name From 4fcac873fa13a8a938bff1cbf7f46e8d2b4ae3c3 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 10 Nov 2026 16:42:33 +0100 Subject: [PATCH 08/44] direct: never send a model's name with new_name A config read back from a saved plan force-sends name, so a rename deployed with --plan sent "name": "" next to new_name, which UC rejects. Co-authored-by: Isaac --- bundle/direct/dresources/registered_model.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bundle/direct/dresources/registered_model.go b/bundle/direct/dresources/registered_model.go index e00fb4f500f..81a88db5dd2 100644 --- a/bundle/direct/dresources/registered_model.go +++ b/bundle/direct/dresources/registered_model.go @@ -92,15 +92,18 @@ func (r *ResourceRegisteredModel) WaitAfterCreate(ctx context.Context, id string var registeredModelForceSend = []string{"Comment"} func makeUpdateRegisteredModel(fullName, newName string, config *catalog.CreateRegisteredModelRequest) catalog.UpdateRegisteredModelRequest { - // UC rejects an update that sets both name and new_name. + // UC rejects an update that sets both name and new_name, even an empty name: a config read back + // from a saved plan force-sends it. name := config.Name + notSent := []string{"Owner", "NewName"} if newName != "" { name = "" + notSent = append(notSent, "Name") } return catalog.UpdateRegisteredModelRequest{ FullName: fullName, Comment: config.Comment, - ForceSendFields: utils.FilterFields[catalog.UpdateRegisteredModelRequest](append(slices.Clone(registeredModelForceSend), config.ForceSendFields...), "Owner", "NewName"), + ForceSendFields: utils.FilterFields[catalog.UpdateRegisteredModelRequest](append(slices.Clone(registeredModelForceSend), config.ForceSendFields...), notSent...), // Owner is settable in the config (it comes from the embedded // CreateRegisteredModelRequest) and create sends it, but update never has: a From 985c68ec59bc17533de7d8541204f3befcdc52e8 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 10 Nov 2026 16:42:36 +0100 Subject: [PATCH 09/44] acc: also deploy registered_models/rename from a saved plan (READPLAN) Co-authored-by: Isaac --- .../resources/registered_models/rename/out.test.toml | 1 + .../bundle/resources/registered_models/rename/script | 8 ++++---- .../bundle/resources/registered_models/rename/test.toml | 7 +++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/acceptance/bundle/resources/registered_models/rename/out.test.toml b/acceptance/bundle/resources/registered_models/rename/out.test.toml index 0f167effef1..7a62f726f25 100644 --- a/acceptance/bundle/resources/registered_models/rename/out.test.toml +++ b/acceptance/bundle/resources/registered_models/rename/out.test.toml @@ -1,2 +1,3 @@ Cloud = true EnvMatrix.DMS = ["", "true"] +EnvMatrix.READPLAN = ["", "1"] diff --git a/acceptance/bundle/resources/registered_models/rename/script b/acceptance/bundle/resources/registered_models/rename/script index 5c057eb0bf5..d2e8cf80c4e 100644 --- a/acceptance/bundle/resources/registered_models/rename/script +++ b/acceptance/bundle/resources/registered_models/rename/script @@ -10,7 +10,7 @@ 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 browse_only effective_predictive_optimization_flag enable_predictive_optimization isolation_mode securable_type storage_location + trace $CLI bundle plan --output json | tee .databricks/plan.json | jq .plan | normalize_uc_payload.py created_at updated_at updated_by metastore_id browse_only effective_predictive_optimization_flag enable_predictive_optimization isolation_mode securable_type storage_location } title "Deploy a catalog with a schema and a registered model in it" @@ -21,21 +21,21 @@ add_repl "$($CLI registered-models get "test_catalog_${UNIQUE_NAME}.myschema.mym title "Rename the model: it is renamed in place, keeping its versions" trace update_file.py databricks.yml "name: mymodel" "name: mymodel2" plan -trace $CLI bundle deploy +trace $CLI bundle deploy $(readplanarg .databricks/plan.json) trace print_requests.py //unity-catalog trace $CLI registered-models get "test_catalog_${UNIQUE_NAME}.myschema.mymodel2" | jq '{full_name, created_at}' title "Rename the schema: UC moves the model with it, so the model is re-keyed without a request" trace update_file.py databricks.yml "name: myschema" "name: myschema2" plan -trace $CLI bundle deploy +trace $CLI bundle deploy $(readplanarg .databricks/plan.json) trace print_requests.py //unity-catalog trace $CLI registered-models get "test_catalog_${UNIQUE_NAME}.myschema2.mymodel2" | jq '{full_name, created_at}' title "Rename the catalog: the model is re-keyed again" trace update_file.py databricks.yml test_catalog_ test_catalog_renamed_ plan -trace $CLI bundle deploy +trace $CLI bundle deploy $(readplanarg .databricks/plan.json) trace print_requests.py //unity-catalog trace $CLI registered-models get "test_catalog_renamed_${UNIQUE_NAME}.myschema2.mymodel2" | jq '{full_name, created_at}' diff --git a/acceptance/bundle/resources/registered_models/rename/test.toml b/acceptance/bundle/resources/registered_models/rename/test.toml index 4272a80cf61..ebd892fd9df 100644 --- a/acceptance/bundle/resources/registered_models/rename/test.toml +++ b/acceptance/bundle/resources/registered_models/rename/test.toml @@ -1,7 +1,14 @@ Cloud = true +EnvMatrix.READPLAN = ["", "1"] Ignore = [ ".databricks", ".gitignore", "databricks.yml", ] + +# When READPLAN=1, "bundle deploy" is called as "bundle deploy --plan .databricks/plan.json". +# Normalize so both variants produce identical output. +[[Repls]] +Old = ' --plan .databricks/plan.json' +New = '' From c9015e9c8d572cb6132b3abf74c7dfe5cc7966b8 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 10:36:24 +0100 Subject: [PATCH 10/44] Make the changelog entry mirror the PR title Co-authored-by: Isaac --- .nextchanges/bundles/registered-model-rename.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/bundles/registered-model-rename.md b/.nextchanges/bundles/registered-model-rename.md index 5cf62805994..8b45402ed03 100644 --- a/.nextchanges/bundles/registered-model-rename.md +++ b/.nextchanges/bundles/registered-model-rename.md @@ -1 +1 @@ -* Rename a registered model in place when its `name` changes, keeping its versions, instead of deleting and recreating it. Registered models inside a renamed catalog or schema now follow it to the new name; recreating them failed because they already exist there. ([#7379](https://github.com/databricks/cli/pull/7379)) +* Rename registered models in place and follow parent renames. ([#7379](https://github.com/databricks/cli/pull/7379)) From 5430ccd247666107616382aa989e3269cb834df9 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 10:40:35 +0100 Subject: [PATCH 11/44] acc: the model follows the schema's rename in rename_with_model_and_secret Co-authored-by: Isaac --- .../rename_with_model_and_secret/output.txt | 21 +++---------------- .../rename_with_model_and_secret/script | 2 +- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/acceptance/bundle/resources/schemas/rename_with_model_and_secret/output.txt b/acceptance/bundle/resources/schemas/rename_with_model_and_secret/output.txt index cd987eb4ca0..18ac6b3162b 100644 --- a/acceptance/bundle/resources/schemas/rename_with_model_and_secret/output.txt +++ b/acceptance/bundle/resources/schemas/rename_with_model_and_secret/output.txt @@ -9,30 +9,24 @@ Created secrets.secret1 Files: 2 uploaded, 0 deleted Resources: 3 created, 0 changed, 0 deleted, 0 unchanged -=== Rename the schema. UC moves the model and the secret with it; they cannot follow a rename yet, so they are recreated where they moved +=== Rename the schema. UC moves the model and the secret with it; the model follows the rename, the secret cannot yet, so it is recreated where it moved >>> update_file.py databricks.yml test-schema- test-schema-renamed- >>> [CLI] bundle plan -recreate registered_models.model1 update schemas.schema1 recreate secrets.secret1 -Plan: 2 to add, 1 to change, 2 to delete, 0 unchanged +Plan: 1 to add, 1 to change, 1 to delete, 1 unchanged >>> [CLI] bundle deploy --auto-approve Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... -Recreated registered_models.model1 Recreated secrets.secret1 Updated schemas.schema1 Files: 2 uploaded, 0 deleted -Resources: 2 created, 1 changed, 2 deleted, 0 unchanged +Resources: 1 created, 1 changed, 1 deleted, 1 unchanged >>> print_requests.py --sort //unity-catalog -{ - "method": "DELETE", - "path": "/api/2.1/unity-catalog/models/main.test-schema-renamed-[UNIQUE_NAME].mymodel" -} { "method": "DELETE", "path": "/api/2.1/unity-catalog/secrets/main.test-schema-renamed-[UNIQUE_NAME].mysecret" @@ -46,15 +40,6 @@ Resources: 2 created, 1 changed, 2 deleted, 0 unchanged "new_name": "test-schema-renamed-[UNIQUE_NAME]" } } -{ - "method": "POST", - "path": "/api/2.1/unity-catalog/models", - "body": { - "catalog_name": "main", - "name": "mymodel", - "schema_name": "test-schema-renamed-[UNIQUE_NAME]" - } -} { "method": "POST", "path": "/api/2.1/unity-catalog/secrets", diff --git a/acceptance/bundle/resources/schemas/rename_with_model_and_secret/script b/acceptance/bundle/resources/schemas/rename_with_model_and_secret/script index af95a0bb084..17140a4e99b 100644 --- a/acceptance/bundle/resources/schemas/rename_with_model_and_secret/script +++ b/acceptance/bundle/resources/schemas/rename_with_model_and_secret/script @@ -15,7 +15,7 @@ title "Deploy a schema with a registered model and a secret in it" trace $CLI bundle deploy print_requests.py //unity-catalog &> LOG.deploy_requests -title "Rename the schema. UC moves the model and the secret with it; they cannot follow a rename yet, so they are recreated where they moved" +title "Rename the schema. UC moves the model and the secret with it; the model follows the rename, the secret cannot yet, so it is recreated where it moved" trace update_file.py databricks.yml test-schema- test-schema-renamed- trace $CLI bundle plan trace $CLI bundle deploy --auto-approve From aaff26191df939fa46157525be6e254e7db52df6 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 10:40:44 +0100 Subject: [PATCH 12/44] acc: regenerate the registered model goldens after rebase Co-authored-by: Isaac --- .../migrate/auto/registered-model-rename/output.txt | 9 ++++----- .../resources/registered_models/basic/output.txt | 10 +++++----- .../resources/registered_models/rename/output.txt | 6 ++++++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/acceptance/bundle/migrate/auto/registered-model-rename/output.txt b/acceptance/bundle/migrate/auto/registered-model-rename/output.txt index a81db3e5b61..3941779024e 100644 --- a/acceptance/bundle/migrate/auto/registered-model-rename/output.txt +++ b/acceptance/bundle/migrate/auto/registered-model-rename/output.txt @@ -3,19 +3,18 @@ >>> replay_tfstate.py terraform-requests.json terraform.tfstate -=== Rename the model (an immutable id field) and deploy on direct +=== Rename the model (an updatable id field) and deploy on direct >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy -Warn: migration to direct: registered_models.my_model: name differs between config ("themodel-[UNIQUE_NAME]-renamed") and terraform state ("themodel-[UNIQUE_NAME]"); this resource will be recreated. +Warn: migration to direct: registered_models.my_model: name differs between config ("themodel-[UNIQUE_NAME]-renamed") and terraform state ("themodel-[UNIQUE_NAME]"); this resource will be renamed. Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files... Migrated 2 resources to direct deployment engine. -Recreated registered_models.my_model +Updated registered_models.my_model Files: 2 uploaded, 0 deleted -Resources: 1 created, 0 changed, 1 deleted, 1 unchanged +Resources: 0 created, 1 changed, 0 deleted, 1 unchanged >>> print_migration_telemetry -direct_migrate_recreate_planned true direct_migrated_via_env true === Redeploy on direct: the model now matches config, so the plan is a clean no-op diff --git a/acceptance/bundle/resources/registered_models/basic/output.txt b/acceptance/bundle/resources/registered_models/basic/output.txt index fb05660caf4..9ee65363440 100644 --- a/acceptance/bundle/resources/registered_models/basic/output.txt +++ b/acceptance/bundle/resources/registered_models/basic/output.txt @@ -61,18 +61,18 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "schema_name": "default" } -=== update the name, this should recreate +=== update the name, this renames the model in place >>> [CLI] bundle plan -recreate registered_models.my_registered_model +update registered_models.my_registered_model -Plan: 1 to add, 0 to change, 1 to delete, 0 unchanged +Plan: 0 to add, 1 to change, 0 to delete, 0 unchanged >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/deploy-registered-models-basic-[UNIQUE_NAME]/default/files... -Recreated registered_models.my_registered_model +Updated registered_models.my_registered_model Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 1 deleted, 0 unchanged +Resources: 0 created, 1 changed, 0 deleted, 0 unchanged >>> [CLI] registered-models get main.default.my-registered-model-updated-[UNIQUE_NAME] { diff --git a/acceptance/bundle/resources/registered_models/rename/output.txt b/acceptance/bundle/resources/registered_models/rename/output.txt index a85544f2483..9546c71c49a 100644 --- a/acceptance/bundle/resources/registered_models/rename/output.txt +++ b/acceptance/bundle/resources/registered_models/rename/output.txt @@ -1,5 +1,6 @@ === Deploy a catalog with a schema and a registered model in it + >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Created catalogs.catalog1 @@ -36,6 +37,7 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged } === Rename the model: it is renamed in place, keeping its versions + >>> update_file.py databricks.yml name: mymodel name: mymodel2 >>> [CLI] bundle plan --output json @@ -157,6 +159,7 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged } === Rename the schema: UC moves the model with it, so the model is re-keyed without a request + >>> update_file.py databricks.yml name: myschema name: myschema2 >>> [CLI] bundle plan --output json @@ -291,6 +294,7 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged } === Rename the catalog: the model is re-keyed again + >>> update_file.py databricks.yml test_catalog_ test_catalog_renamed_ >>> [CLI] bundle plan --output json @@ -452,6 +456,7 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged } === Rename the model and change its comment in one deploy: both go in one PATCH + >>> update_file.py databricks.yml name: mymodel2 name: mymodel3 >>> update_file.py databricks.yml comment: c1 comment: c2 @@ -482,6 +487,7 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged } === The state tracks the new paths and the plan is a no-op + >>> [CLI] bundle summary --output json { "catalogs": { From 562e1a9297af60af9fb9d318ce6b259c34c5f642 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 14:03:03 +0100 Subject: [PATCH 13/44] testserver: report a missing registered model with UC's message Verified on AWS, Azure and GCP: UC answers "Routine or Model '' does not exist." Co-authored-by: Isaac --- libs/testserver/registered_models.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/testserver/registered_models.go b/libs/testserver/registered_models.go index 2dea8ecc864..9f91b98b874 100644 --- a/libs/testserver/registered_models.go +++ b/libs/testserver/registered_models.go @@ -244,7 +244,7 @@ func registeredModelNotFound(fullName string) Response { StatusCode: http.StatusNotFound, Body: map[string]string{ "error_code": "RESOURCE_DOES_NOT_EXIST", - "message": fmt.Sprintf("Registered model '%s' does not exist.", fullName), + "message": fmt.Sprintf("Routine or Model '%s' does not exist.", fullName), }, } } From df69a3921221eaab8f7a19973b776c3b51e75c39 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 14:08:56 +0100 Subject: [PATCH 14/44] acc: a registered model follows a catalog rename in catalogs/rename Co-authored-by: Isaac --- .../catalogs/rename/databricks.yml.tmpl | 5 + .../resources/catalogs/rename/output.txt | 97 ++++++++++++++++--- .../bundle/resources/catalogs/rename/script | 15 +-- 3 files changed, 98 insertions(+), 19 deletions(-) diff --git a/acceptance/bundle/resources/catalogs/rename/databricks.yml.tmpl b/acceptance/bundle/resources/catalogs/rename/databricks.yml.tmpl index e45eccddc44..37a21cc13da 100644 --- a/acceptance/bundle/resources/catalogs/rename/databricks.yml.tmpl +++ b/acceptance/bundle/resources/catalogs/rename/databricks.yml.tmpl @@ -14,3 +14,8 @@ resources: catalog_name: ${resources.catalogs.catalog1.name} schema_name: ${resources.schemas.schema1.name} name: myvolume + registered_models: + model1: + catalog_name: ${resources.catalogs.catalog1.name} + schema_name: ${resources.schemas.schema1.name} + name: mymodel diff --git a/acceptance/bundle/resources/catalogs/rename/output.txt b/acceptance/bundle/resources/catalogs/rename/output.txt index 0d5b9fcb881..5bb6c4b2655 100644 --- a/acceptance/bundle/resources/catalogs/rename/output.txt +++ b/acceptance/bundle/resources/catalogs/rename/output.txt @@ -1,15 +1,16 @@ -=== Deploy a catalog with a schema and a volume in it +=== Deploy a catalog with a schema, a volume and a registered model in it >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Created catalogs.catalog1 +Created registered_models.model1 Created schemas.schema1 Created volumes.volume1 Files: 2 uploaded, 0 deleted -Resources: 3 created, 0 changed, 0 deleted, 0 unchanged +Resources: 4 created, 0 changed, 0 deleted, 0 unchanged ->>> print_requests.py //unity-catalog +>>> print_requests.py --sort //unity-catalog { "method": "POST", "path": "/api/2.1/unity-catalog/catalogs", @@ -17,6 +18,15 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged "name": "test_catalog_[UNIQUE_NAME]" } } +{ + "method": "POST", + "path": "/api/2.1/unity-catalog/models", + "body": { + "catalog_name": "test_catalog_[UNIQUE_NAME]", + "name": "mymodel", + "schema_name": "myschema" + } +} { "method": "POST", "path": "/api/2.1/unity-catalog/schemas", @@ -40,7 +50,7 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged >>> update_file.py databricks.yml test_catalog_ test_catalog_renamed_ -=== UC moves the schema and the volume with the catalog, so the plan re-keys them instead of recreating them +=== UC moves the schema, the volume and the model with the catalog, so the plan re-keys them instead of recreating them >>> [CLI] bundle plan --output json { @@ -53,7 +63,6 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged }, "remote_state": { "catalog_type": "MANAGED_CATALOG", - "created_at": [UNIX_TIME_MILLIS][0], "created_by": "[USERNAME]", "full_name": "test_catalog_[UNIQUE_NAME]", "name": "test_catalog_[UNIQUE_NAME]", @@ -69,6 +78,59 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged } } }, + "resources.registered_models.model1": { + "depends_on": [ + { + "node": "resources.catalogs.catalog1", + "label": "${resources.catalogs.catalog1.name}" + }, + { + "node": "resources.schemas.schema1", + "label": "${resources.schemas.schema1.name}" + } + ], + "action": "update_id", + "state_only": true, + "new_state": { + "value": { + "catalog_name": "test_catalog_renamed_[UNIQUE_NAME]", + "name": "mymodel", + "schema_name": "myschema" + } + }, + "remote_state": { + "catalog_name": "test_catalog_[UNIQUE_NAME]", + "created_by": "[USERNAME]", + "full_name": "test_catalog_[UNIQUE_NAME].myschema.mymodel", + "name": "mymodel", + "owner": "[USERNAME]", + "schema_name": "myschema" + }, + "changes": { + "catalog_name": { + "action": "update_id", + "reason": "parent_renamed", + "old": "test_catalog_[UNIQUE_NAME]", + "new": "test_catalog_renamed_[UNIQUE_NAME]", + "remote": "test_catalog_[UNIQUE_NAME]" + }, + "created_by": { + "action": "skip", + "reason": "output_only", + "remote": "[USERNAME]" + }, + "full_name": { + "action": "skip", + "reason": "backend_default", + "remote": "test_catalog_[UNIQUE_NAME].myschema.mymodel" + }, + "owner": { + "action": "skip", + "reason": "backend_default", + "remote": "[USERNAME]" + } + } + }, "resources.schemas.schema1": { "depends_on": [ { @@ -87,7 +149,6 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged "remote_state": { "catalog_name": "test_catalog_[UNIQUE_NAME]", "catalog_type": "MANAGED_CATALOG", - "created_at": [UNIX_TIME_MILLIS][1], "created_by": "[USERNAME]", "full_name": "test_catalog_[UNIQUE_NAME].myschema", "name": "myschema", @@ -133,7 +194,6 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged }, "remote_state": { "catalog_name": "test_catalog_[UNIQUE_NAME]", - "created_at": [UNIX_TIME_MILLIS][2], "created_by": "[USERNAME]", "full_name": "test_catalog_[UNIQUE_NAME].myschema.myvolume", "name": "myvolume", @@ -160,13 +220,13 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged } } -=== Deploy renames the catalog. UC moves the schema and the volume with it, so they get no request +=== Deploy renames the catalog. UC moves the schema, the volume and the model with it, so they get no request >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Updated catalogs.catalog1 Files: 1 uploaded, 0 deleted -Resources: 0 created, 1 changed, 0 deleted, 2 unchanged +Resources: 0 created, 1 changed, 0 deleted, 3 unchanged >>> print_requests.py //unity-catalog { @@ -179,7 +239,7 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged } } -=== The old catalog is gone and the schema and the volume are under the new one, with their original ids +=== The old catalog is gone and the schema, the volume and the model are under the new one, not recreated old catalog is gone >>> [CLI] schemas get test_catalog_renamed_[UNIQUE_NAME].myschema @@ -196,6 +256,13 @@ old catalog is gone "volume_id": "[VOLUME_ID]" } +>>> [CLI] registered-models get test_catalog_renamed_[UNIQUE_NAME].myschema.mymodel +{ + "full_name": "test_catalog_renamed_[UNIQUE_NAME].myschema.mymodel", + "catalog_name": "test_catalog_renamed_[UNIQUE_NAME]", + "created_at": [MODEL_CREATED_AT] +} + === The state tracks the new paths >>> [CLI] bundle summary --output json @@ -203,6 +270,9 @@ old catalog is gone "catalogs": { "catalog1": "test_catalog_renamed_[UNIQUE_NAME]" }, + "registered_models": { + "model1": "test_catalog_renamed_[UNIQUE_NAME].myschema.mymodel" + }, "schemas": { "schema1": "test_catalog_renamed_[UNIQUE_NAME].myschema" }, @@ -214,18 +284,19 @@ old catalog is gone === Redeploy is a no-op >>> [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged +Plan: 0 to add, 0 to change, 0 to delete, 4 unchanged >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Files: 0 uploaded, 0 deleted -Resources: 0 created, 0 changed, 0 deleted, 3 unchanged +Resources: 0 created, 0 changed, 0 deleted, 4 unchanged >>> print_requests.py //unity-catalog >>> [CLI] bundle destroy --auto-approve The following resources will be deleted: delete resources.catalogs.catalog1 + delete resources.registered_models.model1 delete resources.schemas.schema1 delete resources.volumes.volume1 @@ -240,4 +311,4 @@ is removed from the catalog, but the underlying files are not deleted: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default -Destroy: 3 deleted +Destroy: 4 deleted diff --git a/acceptance/bundle/resources/catalogs/rename/script b/acceptance/bundle/resources/catalogs/rename/script index 1b20c07091b..30c98f549ca 100644 --- a/acceptance/bundle/resources/catalogs/rename/script +++ b/acceptance/bundle/resources/catalogs/rename/script @@ -11,28 +11,31 @@ cleanup() { } trap cleanup EXIT -title "Deploy a catalog with a schema and a volume in it" +title "Deploy a catalog with a schema, a volume and a registered model in it" trace $CLI bundle deploy -trace print_requests.py //unity-catalog +# The volume and the model are created in parallel. +trace print_requests.py --sort //unity-catalog add_repl "$($CLI schemas get "$OLD_CATALOG.myschema" | jq -r .schema_id)" SCHEMA_ID add_repl "$($CLI volumes read "$OLD_CATALOG.myschema.myvolume" | jq -r .volume_id)" VOLUME_ID +add_repl "$($CLI registered-models get "$OLD_CATALOG.myschema.mymodel" | jq -r .created_at)" MODEL_CREATED_AT title "Rename the catalog" trace update_file.py databricks.yml test_catalog_ test_catalog_renamed_ -title "UC moves the schema and the volume with the catalog, so the plan re-keys them instead of recreating them" +title "UC moves the schema, the volume and the model with the catalog, so the plan re-keys them instead of recreating them" # Drop the remote_state fields that differ between clouds or from the test server. -trace $CLI bundle plan --output json | tee .databricks/plan.json | jq .plan | normalize_uc_payload.py updated_at updated_by metastore_id browse_only effective_predictive_optimization_flag enable_predictive_optimization isolation_mode securable_type storage_location +trace $CLI bundle plan --output json | tee .databricks/plan.json | jq .plan | normalize_uc_payload.py created_at updated_at updated_by metastore_id browse_only effective_predictive_optimization_flag enable_predictive_optimization isolation_mode securable_type storage_location -title "Deploy renames the catalog. UC moves the schema and the volume with it, so they get no request" +title "Deploy renames the catalog. UC moves the schema, the volume and the model with it, so they get no request" trace $CLI bundle deploy $(readplanarg .databricks/plan.json) trace print_requests.py //unity-catalog -title "The old catalog is gone and the schema and the volume are under the new one, with their original ids" +title "The old catalog is gone and the schema, the volume and the model are under the new one, not recreated" # Not traced: the "not found" message differs between UC and the test server. $CLI catalogs get "$OLD_CATALOG" &> /dev/null && echo "old catalog still exists" || echo "old catalog is gone" trace $CLI schemas get "$NEW_CATALOG.myschema" | jq '{full_name, catalog_name, schema_id}' trace $CLI volumes read "$NEW_CATALOG.myschema.myvolume" | jq '{full_name, catalog_name, volume_id}' +trace $CLI registered-models get "$NEW_CATALOG.myschema.mymodel" | jq '{full_name, catalog_name, created_at}' title "The state tracks the new paths" trace $CLI bundle summary --output json | jq '.resources | map_values(map_values(.id))' From 9eb8916231b0e13c3329af61aa1772d2a0cb07a0 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 14:08:57 +0100 Subject: [PATCH 15/44] acc: a registered model follows its catalog and schema renamed in one deploy Co-authored-by: Isaac --- .../databricks.yml.tmpl | 5 ++ .../rename_catalog_and_schema/output.txt | 90 ++++++++++++++++--- .../volumes/rename_catalog_and_schema/script | 12 +-- 3 files changed, 91 insertions(+), 16 deletions(-) diff --git a/acceptance/bundle/resources/volumes/rename_catalog_and_schema/databricks.yml.tmpl b/acceptance/bundle/resources/volumes/rename_catalog_and_schema/databricks.yml.tmpl index e45eccddc44..37a21cc13da 100644 --- a/acceptance/bundle/resources/volumes/rename_catalog_and_schema/databricks.yml.tmpl +++ b/acceptance/bundle/resources/volumes/rename_catalog_and_schema/databricks.yml.tmpl @@ -14,3 +14,8 @@ resources: catalog_name: ${resources.catalogs.catalog1.name} schema_name: ${resources.schemas.schema1.name} name: myvolume + registered_models: + model1: + catalog_name: ${resources.catalogs.catalog1.name} + schema_name: ${resources.schemas.schema1.name} + name: mymodel diff --git a/acceptance/bundle/resources/volumes/rename_catalog_and_schema/output.txt b/acceptance/bundle/resources/volumes/rename_catalog_and_schema/output.txt index f5d7df1a699..3f62d48457a 100644 --- a/acceptance/bundle/resources/volumes/rename_catalog_and_schema/output.txt +++ b/acceptance/bundle/resources/volumes/rename_catalog_and_schema/output.txt @@ -1,13 +1,14 @@ -=== Deploy a catalog with a schema and a volume in it +=== Deploy a catalog with a schema, a volume and a registered model in it >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Created catalogs.catalog1 +Created registered_models.model1 Created schemas.schema1 Created volumes.volume1 Files: 2 uploaded, 0 deleted -Resources: 3 created, 0 changed, 0 deleted, 0 unchanged +Resources: 4 created, 0 changed, 0 deleted, 0 unchanged === Rename the catalog and the schema in one deploy @@ -15,7 +16,7 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged >>> update_file.py databricks.yml name: myschema name: myschema2 -=== Both of the volume's parents are renamed, so both its catalog_name and schema_name follow them +=== Both parents of the volume and the model are renamed, so both their catalog_name and schema_name follow them >>> [CLI] bundle plan --output json { @@ -28,7 +29,6 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged }, "remote_state": { "catalog_type": "MANAGED_CATALOG", - "created_at": [UNIX_TIME_MILLIS][0], "created_by": "[USERNAME]", "full_name": "test_catalog_[UNIQUE_NAME]", "name": "test_catalog_[UNIQUE_NAME]", @@ -44,6 +44,66 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged } } }, + "resources.registered_models.model1": { + "depends_on": [ + { + "node": "resources.catalogs.catalog1", + "label": "${resources.catalogs.catalog1.name}" + }, + { + "node": "resources.schemas.schema1", + "label": "${resources.schemas.schema1.name}" + } + ], + "action": "update_id", + "state_only": true, + "new_state": { + "value": { + "catalog_name": "test_catalog_renamed_[UNIQUE_NAME]", + "name": "mymodel", + "schema_name": "myschema2" + } + }, + "remote_state": { + "catalog_name": "test_catalog_[UNIQUE_NAME]", + "created_by": "[USERNAME]", + "full_name": "test_catalog_[UNIQUE_NAME].myschema.mymodel", + "name": "mymodel", + "owner": "[USERNAME]", + "schema_name": "myschema" + }, + "changes": { + "catalog_name": { + "action": "update_id", + "reason": "parent_renamed", + "old": "test_catalog_[UNIQUE_NAME]", + "new": "test_catalog_renamed_[UNIQUE_NAME]", + "remote": "test_catalog_[UNIQUE_NAME]" + }, + "created_by": { + "action": "skip", + "reason": "output_only", + "remote": "[USERNAME]" + }, + "full_name": { + "action": "skip", + "reason": "backend_default", + "remote": "test_catalog_[UNIQUE_NAME].myschema.mymodel" + }, + "owner": { + "action": "skip", + "reason": "backend_default", + "remote": "[USERNAME]" + }, + "schema_name": { + "action": "update_id", + "reason": "parent_renamed", + "old": "myschema", + "new": "myschema2", + "remote": "myschema" + } + } + }, "resources.schemas.schema1": { "depends_on": [ { @@ -61,7 +121,6 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged "remote_state": { "catalog_name": "test_catalog_[UNIQUE_NAME]", "catalog_type": "MANAGED_CATALOG", - "created_at": [UNIX_TIME_MILLIS][1], "created_by": "[USERNAME]", "full_name": "test_catalog_[UNIQUE_NAME].myschema", "name": "myschema", @@ -114,7 +173,6 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged }, "remote_state": { "catalog_name": "test_catalog_[UNIQUE_NAME]", - "created_at": [UNIX_TIME_MILLIS][2], "created_by": "[USERNAME]", "full_name": "test_catalog_[UNIQUE_NAME].myschema.myvolume", "name": "myvolume", @@ -148,14 +206,14 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged } } -=== Deploy renames the catalog, then the schema under it. UC moves the volume both times, so it gets no request +=== Deploy renames the catalog, then the schema under it. UC moves the volume and the model both times, so they get no request >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Updated catalogs.catalog1 Updated schemas.schema1 Files: 2 uploaded, 0 deleted -Resources: 0 created, 2 changed, 0 deleted, 1 unchanged +Resources: 0 created, 2 changed, 0 deleted, 2 unchanged >>> print_requests.py //unity-catalog { @@ -177,7 +235,7 @@ Resources: 0 created, 2 changed, 0 deleted, 1 unchanged } } -=== The schema and the volume are under the new names, with their original ids +=== The schema, the volume and the model are under the new names, not recreated >>> [CLI] schemas get test_catalog_renamed_[UNIQUE_NAME].myschema2 { @@ -191,11 +249,20 @@ Resources: 0 created, 2 changed, 0 deleted, 1 unchanged "volume_id": "[VOLUME_ID]" } +>>> [CLI] registered-models get test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel +{ + "full_name": "test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel", + "created_at": [MODEL_CREATED_AT] +} + >>> [CLI] bundle summary --output json { "catalogs": { "catalog1": "test_catalog_renamed_[UNIQUE_NAME]" }, + "registered_models": { + "model1": "test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel" + }, "schemas": { "schema1": "test_catalog_renamed_[UNIQUE_NAME].myschema2" }, @@ -207,11 +274,12 @@ Resources: 0 created, 2 changed, 0 deleted, 1 unchanged === Redeploy is a no-op >>> [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged +Plan: 0 to add, 0 to change, 0 to delete, 4 unchanged >>> [CLI] bundle destroy --auto-approve The following resources will be deleted: delete resources.catalogs.catalog1 + delete resources.registered_models.model1 delete resources.schemas.schema1 delete resources.volumes.volume1 @@ -226,4 +294,4 @@ is removed from the catalog, but the underlying files are not deleted: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default -Destroy: 3 deleted +Destroy: 4 deleted diff --git a/acceptance/bundle/resources/volumes/rename_catalog_and_schema/script b/acceptance/bundle/resources/volumes/rename_catalog_and_schema/script index 2f0b71af10b..5a1f553ab7b 100644 --- a/acceptance/bundle/resources/volumes/rename_catalog_and_schema/script +++ b/acceptance/bundle/resources/volumes/rename_catalog_and_schema/script @@ -10,27 +10,29 @@ cleanup() { } trap cleanup EXIT -title "Deploy a catalog with a schema and a volume in it" +title "Deploy a catalog with a schema, a volume and a registered model in it" trace $CLI bundle deploy print_requests.py //unity-catalog &> LOG.deploy_requests add_repl "$($CLI schemas get "test_catalog_${UNIQUE_NAME}.myschema" | jq -r .schema_id)" SCHEMA_ID add_repl "$($CLI volumes read "test_catalog_${UNIQUE_NAME}.myschema.myvolume" | jq -r .volume_id)" VOLUME_ID +add_repl "$($CLI registered-models get "test_catalog_${UNIQUE_NAME}.myschema.mymodel" | jq -r .created_at)" MODEL_CREATED_AT title "Rename the catalog and the schema in one deploy" trace update_file.py databricks.yml test_catalog_ test_catalog_renamed_ trace update_file.py databricks.yml "name: myschema" "name: myschema2" -title "Both of the volume's parents are renamed, so both its catalog_name and schema_name follow them" +title "Both parents of the volume and the model are renamed, so both their catalog_name and schema_name follow them" # Drop the remote_state fields that differ between clouds or from the test server. -trace $CLI bundle plan --output json | tee .databricks/plan.json | jq .plan | normalize_uc_payload.py updated_at updated_by metastore_id browse_only effective_predictive_optimization_flag enable_predictive_optimization isolation_mode securable_type storage_location +trace $CLI bundle plan --output json | tee .databricks/plan.json | jq .plan | normalize_uc_payload.py created_at updated_at updated_by metastore_id browse_only effective_predictive_optimization_flag enable_predictive_optimization isolation_mode securable_type storage_location -title "Deploy renames the catalog, then the schema under it. UC moves the volume both times, so it gets no request" +title "Deploy renames the catalog, then the schema under it. UC moves the volume and the model both times, so they get no request" trace $CLI bundle deploy $(readplanarg .databricks/plan.json) trace print_requests.py //unity-catalog -title "The schema and the volume are under the new names, with their original ids" +title "The schema, the volume and the model are under the new names, not recreated" trace $CLI schemas get "$NEW_SCHEMA" | jq '{full_name, schema_id}' trace $CLI volumes read "$NEW_SCHEMA.myvolume" | jq '{full_name, volume_id}' +trace $CLI registered-models get "$NEW_SCHEMA.mymodel" | jq '{full_name, created_at}' trace $CLI bundle summary --output json | jq '.resources | map_values(map_values(.id))' title "Redeploy is a no-op" From 2ceab9cf5bcd88293a3dda673a52b76ae9fcf7e1 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 14:08:58 +0100 Subject: [PATCH 16/44] acc: update, rename and recreate a registered model after its schema is renamed Co-authored-by: Isaac --- .../rename_then_change/databricks.yml.tmpl | 6 + .../schemas/rename_then_change/output.txt | 153 ++++++++++++++---- .../schemas/rename_then_change/script | 20 ++- 3 files changed, 144 insertions(+), 35 deletions(-) diff --git a/acceptance/bundle/resources/schemas/rename_then_change/databricks.yml.tmpl b/acceptance/bundle/resources/schemas/rename_then_change/databricks.yml.tmpl index 663acec3be0..c198551c991 100644 --- a/acceptance/bundle/resources/schemas/rename_then_change/databricks.yml.tmpl +++ b/acceptance/bundle/resources/schemas/rename_then_change/databricks.yml.tmpl @@ -15,3 +15,9 @@ resources: schema_name: ${resources.schemas.schema1.name} name: myvolume comment: c1 + registered_models: + model1: + catalog_name: main + schema_name: ${resources.schemas.schema1.name} + name: mymodel + comment: c1 diff --git a/acceptance/bundle/resources/schemas/rename_then_change/output.txt b/acceptance/bundle/resources/schemas/rename_then_change/output.txt index 8218075b830..1e992b990d8 100644 --- a/acceptance/bundle/resources/schemas/rename_then_change/output.txt +++ b/acceptance/bundle/resources/schemas/rename_then_change/output.txt @@ -1,15 +1,26 @@ -=== Deploy two schemas and a volume in the first one +=== Deploy two schemas, and a volume and a registered model in the first one >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Created registered_models.model1 Created schemas.schema1 Created schemas.schema2 Created volumes.volume1 Files: 2 uploaded, 0 deleted -Resources: 3 created, 0 changed, 0 deleted, 0 unchanged +Resources: 4 created, 0 changed, 0 deleted, 0 unchanged >>> print_requests.py --sort //unity-catalog +{ + "method": "POST", + "path": "/api/2.1/unity-catalog/models", + "body": { + "catalog_name": "main", + "comment": "c1", + "name": "mymodel", + "schema_name": "test-schema1-[UNIQUE_NAME]" + } +} { "method": "POST", "path": "/api/2.1/unity-catalog/schemas", @@ -38,7 +49,7 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged } } -=== Rename the volume's schema: the volume is re-keyed without a request +=== Rename the first schema: the volume and the model are re-keyed without a request >>> update_file.py databricks.yml test-schema1- test-schema1-renamed- @@ -46,9 +57,9 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Updated schemas.schema1 Files: 1 uploaded, 0 deleted -Resources: 0 created, 1 changed, 0 deleted, 2 unchanged +Resources: 0 created, 1 changed, 0 deleted, 3 unchanged ->>> print_requests.py //unity-catalog +>>> print_requests.py --sort //unity-catalog { "method": "PATCH", "path": "/api/2.1/unity-catalog/schemas/main.test-schema1-[UNIQUE_NAME]", @@ -59,17 +70,28 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged } } -=== After the rename, update, update_id and recreate of the volume all reach it at its new path +=== After the rename, update, update_id and recreate of the volume and the model all reach them at their new paths >>> update_file.py databricks.yml comment: c1 comment: c2 >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Updated registered_models.model1 Updated volumes.volume1 Files: 1 uploaded, 0 deleted -Resources: 0 created, 1 changed, 0 deleted, 2 unchanged +Resources: 0 created, 2 changed, 0 deleted, 2 unchanged ->>> print_requests.py //unity-catalog +>>> print_requests.py --sort //unity-catalog +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/models/main.test-schema1-renamed-[UNIQUE_NAME].mymodel", + "body": { + "catalog_name": "main", + "comment": "c2", + "name": "mymodel", + "schema_name": "test-schema1-renamed-[UNIQUE_NAME]" + } +} { "method": "PATCH", "path": "/api/2.1/unity-catalog/volumes/main.test-schema1-renamed-[UNIQUE_NAME].myvolume", @@ -80,13 +102,26 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged >>> update_file.py databricks.yml name: myvolume name: myvolume2 +>>> update_file.py databricks.yml name: mymodel name: mymodel2 + >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Updated registered_models.model1 Updated volumes.volume1 Files: 1 uploaded, 0 deleted -Resources: 0 created, 1 changed, 0 deleted, 2 unchanged +Resources: 0 created, 2 changed, 0 deleted, 2 unchanged ->>> print_requests.py //unity-catalog +>>> print_requests.py --sort //unity-catalog +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/models/main.test-schema1-renamed-[UNIQUE_NAME].mymodel", + "body": { + "catalog_name": "main", + "comment": "c2", + "new_name": "mymodel2", + "schema_name": "test-schema1-renamed-[UNIQUE_NAME]" + } +} { "method": "PATCH", "path": "/api/2.1/unity-catalog/volumes/main.test-schema1-renamed-[UNIQUE_NAME].myvolume", @@ -106,15 +141,30 @@ 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: recreate resources.volumes.volume1 +Recreated registered_models.model1 Recreated volumes.volume1 Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 1 deleted, 2 unchanged +Resources: 2 created, 0 changed, 2 deleted, 2 unchanged ->>> print_requests.py //unity-catalog +>>> print_requests.py --sort //unity-catalog +{ + "method": "DELETE", + "path": "/api/2.1/unity-catalog/models/main.test-schema1-renamed-[UNIQUE_NAME].mymodel2" +} { "method": "DELETE", "path": "/api/2.1/unity-catalog/volumes/main.test-schema1-renamed-[UNIQUE_NAME].myvolume2" } +{ + "method": "POST", + "path": "/api/2.1/unity-catalog/models", + "body": { + "catalog_name": "main", + "comment": "c2", + "name": "mymodel2", + "schema_name": "test-schema2-[UNIQUE_NAME]" + } +} { "method": "POST", "path": "/api/2.1/unity-catalog/volumes", @@ -127,7 +177,7 @@ Resources: 1 created, 0 changed, 1 deleted, 2 unchanged } } -=== Rename the volume's new schema: the volume is re-keyed again +=== Rename the second schema: the volume and the model are re-keyed again >>> update_file.py databricks.yml test-schema2- test-schema2-renamed- @@ -135,9 +185,9 @@ Resources: 1 created, 0 changed, 1 deleted, 2 unchanged Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Updated schemas.schema2 Files: 1 uploaded, 0 deleted -Resources: 0 created, 1 changed, 0 deleted, 2 unchanged +Resources: 0 created, 1 changed, 0 deleted, 3 unchanged ->>> print_requests.py //unity-catalog +>>> print_requests.py --sort //unity-catalog { "method": "PATCH", "path": "/api/2.1/unity-catalog/schemas/main.test-schema2-[UNIQUE_NAME]", @@ -148,17 +198,28 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged } } -=== Update, update_id and recreate work again, moving the volume back to the first schema +=== Update, update_id and recreate work again, moving the volume and the model back to the first schema >>> update_file.py databricks.yml comment: c2 comment: c3 >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Updated registered_models.model1 Updated volumes.volume1 Files: 1 uploaded, 0 deleted -Resources: 0 created, 1 changed, 0 deleted, 2 unchanged +Resources: 0 created, 2 changed, 0 deleted, 2 unchanged ->>> print_requests.py //unity-catalog +>>> print_requests.py --sort //unity-catalog +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/models/main.test-schema2-renamed-[UNIQUE_NAME].mymodel2", + "body": { + "catalog_name": "main", + "comment": "c3", + "name": "mymodel2", + "schema_name": "test-schema2-renamed-[UNIQUE_NAME]" + } +} { "method": "PATCH", "path": "/api/2.1/unity-catalog/volumes/main.test-schema2-renamed-[UNIQUE_NAME].myvolume2", @@ -169,13 +230,26 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged >>> update_file.py databricks.yml name: myvolume2 name: myvolume +>>> update_file.py databricks.yml name: mymodel2 name: mymodel + >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Updated registered_models.model1 Updated volumes.volume1 Files: 1 uploaded, 0 deleted -Resources: 0 created, 1 changed, 0 deleted, 2 unchanged +Resources: 0 created, 2 changed, 0 deleted, 2 unchanged ->>> print_requests.py //unity-catalog +>>> print_requests.py --sort //unity-catalog +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/models/main.test-schema2-renamed-[UNIQUE_NAME].mymodel2", + "body": { + "catalog_name": "main", + "comment": "c3", + "new_name": "mymodel", + "schema_name": "test-schema2-renamed-[UNIQUE_NAME]" + } +} { "method": "PATCH", "path": "/api/2.1/unity-catalog/volumes/main.test-schema2-renamed-[UNIQUE_NAME].myvolume2", @@ -195,15 +269,30 @@ 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: recreate resources.volumes.volume1 +Recreated registered_models.model1 Recreated volumes.volume1 Files: 1 uploaded, 0 deleted -Resources: 1 created, 0 changed, 1 deleted, 2 unchanged +Resources: 2 created, 0 changed, 2 deleted, 2 unchanged ->>> print_requests.py //unity-catalog +>>> print_requests.py --sort //unity-catalog +{ + "method": "DELETE", + "path": "/api/2.1/unity-catalog/models/main.test-schema2-renamed-[UNIQUE_NAME].mymodel" +} { "method": "DELETE", "path": "/api/2.1/unity-catalog/volumes/main.test-schema2-renamed-[UNIQUE_NAME].myvolume" } +{ + "method": "POST", + "path": "/api/2.1/unity-catalog/models", + "body": { + "catalog_name": "main", + "comment": "c3", + "name": "mymodel", + "schema_name": "test-schema1-renamed-[UNIQUE_NAME]" + } +} { "method": "POST", "path": "/api/2.1/unity-catalog/volumes", @@ -216,7 +305,7 @@ Resources: 1 created, 0 changed, 1 deleted, 2 unchanged } } -=== Rename the first schema back: the volume is re-keyed to its original path +=== Rename the first schema back: the volume and the model are re-keyed to their original paths >>> update_file.py databricks.yml test-schema1-renamed- test-schema1- @@ -224,9 +313,9 @@ Resources: 1 created, 0 changed, 1 deleted, 2 unchanged Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Updated schemas.schema1 Files: 1 uploaded, 0 deleted -Resources: 0 created, 1 changed, 0 deleted, 2 unchanged +Resources: 0 created, 1 changed, 0 deleted, 3 unchanged ->>> print_requests.py //unity-catalog +>>> print_requests.py --sort //unity-catalog { "method": "PATCH", "path": "/api/2.1/unity-catalog/schemas/main.test-schema1-renamed-[UNIQUE_NAME]", @@ -241,6 +330,9 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged >>> [CLI] bundle summary --output json { + "registered_models": { + "model1": "main.test-schema1-[UNIQUE_NAME].mymodel" + }, "schemas": { "schema1": "main.test-schema1-[UNIQUE_NAME]", "schema2": "main.test-schema2-renamed-[UNIQUE_NAME]" @@ -251,7 +343,7 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged } >>> [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged +Plan: 0 to add, 0 to change, 0 to delete, 4 unchanged >>> [CLI] volumes read main.test-schema1-[UNIQUE_NAME].myvolume { @@ -259,8 +351,15 @@ Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged "comment": "c3" } +>>> [CLI] registered-models get main.test-schema1-[UNIQUE_NAME].mymodel +{ + "full_name": "main.test-schema1-[UNIQUE_NAME].mymodel", + "comment": "c3" +} + >>> [CLI] bundle destroy --auto-approve The following resources will be deleted: + delete resources.registered_models.model1 delete resources.schemas.schema1 delete resources.schemas.schema2 delete resources.volumes.volume1 @@ -277,4 +376,4 @@ is removed from the catalog, but the underlying files are not deleted: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default -Destroy: 3 deleted +Destroy: 4 deleted diff --git a/acceptance/bundle/resources/schemas/rename_then_change/script b/acceptance/bundle/resources/schemas/rename_then_change/script index 452af92148c..8a2579b1b5f 100644 --- a/acceptance/bundle/resources/schemas/rename_then_change/script +++ b/acceptance/bundle/resources/schemas/rename_then_change/script @@ -10,39 +10,42 @@ trap cleanup EXIT deploy() { trace $CLI bundle deploy "$@" - trace print_requests.py //unity-catalog + # The volume and the model are updated in parallel. + trace print_requests.py --sort //unity-catalog } -title "Deploy two schemas and a volume in the first one" +title "Deploy two schemas, and a volume and a registered model in the first one" trace $CLI bundle deploy -# The two schemas are created in parallel. +# The two schemas, then the volume and the model, are created in parallel. trace print_requests.py --sort //unity-catalog -title "Rename the volume's schema: the volume is re-keyed without a request" +title "Rename the first schema: the volume and the model are re-keyed without a request" trace update_file.py databricks.yml test-schema1- test-schema1-renamed- deploy -title "After the rename, update, update_id and recreate of the volume all reach it at its new path" +title "After the rename, update, update_id and recreate of the volume and the model all reach them at their new paths" trace update_file.py databricks.yml "comment: c1" "comment: c2" deploy trace update_file.py databricks.yml "name: myvolume" "name: myvolume2" +trace update_file.py databricks.yml "name: mymodel" "name: mymodel2" deploy trace update_file.py databricks.yml schemas.schema1.name schemas.schema2.name deploy --auto-approve -title "Rename the volume's new schema: the volume is re-keyed again" +title "Rename the second schema: the volume and the model are re-keyed again" trace update_file.py databricks.yml test-schema2- test-schema2-renamed- deploy -title "Update, update_id and recreate work again, moving the volume back to the first schema" +title "Update, update_id and recreate work again, moving the volume and the model back to the first schema" trace update_file.py databricks.yml "comment: c2" "comment: c3" deploy trace update_file.py databricks.yml "name: myvolume2" "name: myvolume" +trace update_file.py databricks.yml "name: mymodel2" "name: mymodel" deploy trace update_file.py databricks.yml schemas.schema2.name schemas.schema1.name deploy --auto-approve -title "Rename the first schema back: the volume is re-keyed to its original path" +title "Rename the first schema back: the volume and the model are re-keyed to their original paths" trace update_file.py databricks.yml test-schema1-renamed- test-schema1- deploy @@ -50,3 +53,4 @@ title "The state tracks the current paths and the plan is a no-op" trace $CLI bundle summary --output json | jq '.resources | map_values(map_values(.id))' trace $CLI bundle plan trace $CLI volumes read "main.test-schema1-${UNIQUE_NAME}.myvolume" | jq '{full_name, comment}' +trace $CLI registered-models get "main.test-schema1-${UNIQUE_NAME}.mymodel" | jq '{full_name, comment}' From 4c319ccda7160c6a5664cb06da07edc4dc41416d Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 14:08:59 +0100 Subject: [PATCH 17/44] acc: a registered model moved out of a renamed schema is deleted where the rename moved it Co-authored-by: Isaac --- .../databricks.yml.tmpl | 5 + .../move_from_renamed_schema/output.txt | 99 ++++++++++++++++--- .../volumes/move_from_renamed_schema/script | 15 ++- 3 files changed, 103 insertions(+), 16 deletions(-) diff --git a/acceptance/bundle/resources/volumes/move_from_renamed_schema/databricks.yml.tmpl b/acceptance/bundle/resources/volumes/move_from_renamed_schema/databricks.yml.tmpl index 01d93162314..8f4fb91631a 100644 --- a/acceptance/bundle/resources/volumes/move_from_renamed_schema/databricks.yml.tmpl +++ b/acceptance/bundle/resources/volumes/move_from_renamed_schema/databricks.yml.tmpl @@ -14,3 +14,8 @@ resources: catalog_name: main schema_name: ${resources.schemas.schema1.name} name: myvolume + registered_models: + model1: + catalog_name: main + schema_name: ${resources.schemas.schema1.name} + name: mymodel diff --git a/acceptance/bundle/resources/volumes/move_from_renamed_schema/output.txt b/acceptance/bundle/resources/volumes/move_from_renamed_schema/output.txt index c265ef49c8d..844eacac5c4 100644 --- a/acceptance/bundle/resources/volumes/move_from_renamed_schema/output.txt +++ b/acceptance/bundle/resources/volumes/move_from_renamed_schema/output.txt @@ -1,15 +1,16 @@ -=== Deploy two schemas and a volume in the first one +=== Deploy two schemas, and a volume and a registered model in the first one >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Created registered_models.model1 Created schemas.schema1 Created schemas.schema2 Created volumes.volume1 Files: 2 uploaded, 0 deleted -Resources: 3 created, 0 changed, 0 deleted, 0 unchanged +Resources: 4 created, 0 changed, 0 deleted, 0 unchanged -=== Rename the first schema and move the volume to the second one in one deploy. Moving the volume recreates it +=== Rename the first schema and move the volume and the model to the second one in one deploy. Moving them recreates them >>> update_file.py databricks.yml test-schema1- test-schema1-renamed- @@ -17,6 +18,59 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged >>> [CLI] bundle plan --output json { + "resources.registered_models.model1": { + "id": "main.test-schema1-renamed-[UNIQUE_NAME].mymodel", + "depends_on": [ + { + "node": "resources.schemas.schema2", + "label": "${resources.schemas.schema2.name}" + }, + { + "node": "resources.schemas.schema1", + "label": "${resources.schemas.schema1.name}" + } + ], + "action": "recreate", + "new_state": { + "value": { + "catalog_name": "main", + "name": "mymodel", + "schema_name": "test-schema2-[UNIQUE_NAME]" + } + }, + "remote_state": { + "catalog_name": "main", + "created_by": "[USERNAME]", + "full_name": "main.test-schema1-[UNIQUE_NAME].mymodel", + "name": "mymodel", + "owner": "[USERNAME]", + "schema_name": "test-schema1-[UNIQUE_NAME]" + }, + "changes": { + "created_by": { + "action": "skip", + "reason": "output_only", + "remote": "[USERNAME]" + }, + "full_name": { + "action": "skip", + "reason": "backend_default", + "remote": "main.test-schema1-[UNIQUE_NAME].mymodel" + }, + "owner": { + "action": "skip", + "reason": "backend_default", + "remote": "[USERNAME]" + }, + "schema_name": { + "action": "recreate", + "reason": "id_field", + "old": "test-schema1-[UNIQUE_NAME]", + "new": "test-schema2-[UNIQUE_NAME]", + "remote": "test-schema1-[UNIQUE_NAME]" + } + } + }, "resources.schemas.schema1": { "action": "update_id", "new_state": { @@ -131,12 +185,21 @@ 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: recreate resources.volumes.volume1 +Recreated registered_models.model1 Recreated volumes.volume1 Updated schemas.schema1 Files: 2 uploaded, 0 deleted -Resources: 1 created, 1 changed, 1 deleted, 1 unchanged +Resources: 2 created, 1 changed, 2 deleted, 1 unchanged ->>> print_requests.py //unity-catalog +>>> print_requests.py --sort //unity-catalog +{ + "method": "DELETE", + "path": "/api/2.1/unity-catalog/models/main.test-schema1-renamed-[UNIQUE_NAME].mymodel" +} +{ + "method": "DELETE", + "path": "/api/2.1/unity-catalog/volumes/main.test-schema1-renamed-[UNIQUE_NAME].myvolume" +} { "method": "PATCH", "path": "/api/2.1/unity-catalog/schemas/main.test-schema1-[UNIQUE_NAME]", @@ -147,8 +210,13 @@ Resources: 1 created, 1 changed, 1 deleted, 1 unchanged } } { - "method": "DELETE", - "path": "/api/2.1/unity-catalog/volumes/main.test-schema1-renamed-[UNIQUE_NAME].myvolume" + "method": "POST", + "path": "/api/2.1/unity-catalog/models", + "body": { + "catalog_name": "main", + "name": "mymodel", + "schema_name": "test-schema2-[UNIQUE_NAME]" + } } { "method": "POST", @@ -161,25 +229,34 @@ Resources: 1 created, 1 changed, 1 deleted, 1 unchanged } } -=== The volume is in the second schema +=== The volume and the model are in the second schema >>> [CLI] volumes read main.test-schema2-[UNIQUE_NAME].myvolume { "full_name": "main.test-schema2-[UNIQUE_NAME].myvolume" } -=== The old volume, moved with the renamed schema, was deleted there +>>> [CLI] registered-models get main.test-schema2-[UNIQUE_NAME].mymodel +{ + "full_name": "main.test-schema2-[UNIQUE_NAME].mymodel" +} + +=== The old volume and model, moved with the renamed schema, were deleted there >>> musterr [CLI] volumes read main.test-schema1-renamed-[UNIQUE_NAME].myvolume Error: Volume 'main.test-schema1-renamed-[UNIQUE_NAME].myvolume' does not exist. +>>> musterr [CLI] registered-models get main.test-schema1-renamed-[UNIQUE_NAME].mymodel +Error: Routine or Model 'main.test-schema1-renamed-[UNIQUE_NAME].mymodel' does not exist. + === Redeploy is a no-op >>> [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged +Plan: 0 to add, 0 to change, 0 to delete, 4 unchanged >>> [CLI] bundle destroy --auto-approve The following resources will be deleted: + delete resources.registered_models.model1 delete resources.schemas.schema1 delete resources.schemas.schema2 delete resources.volumes.volume1 @@ -196,4 +273,4 @@ is removed from the catalog, but the underlying files are not deleted: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default -Destroy: 3 deleted +Destroy: 4 deleted diff --git a/acceptance/bundle/resources/volumes/move_from_renamed_schema/script b/acceptance/bundle/resources/volumes/move_from_renamed_schema/script index 5d038da5e21..9e6284c4726 100644 --- a/acceptance/bundle/resources/volumes/move_from_renamed_schema/script +++ b/acceptance/bundle/resources/volumes/move_from_renamed_schema/script @@ -2,6 +2,8 @@ envsubst < databricks.yml.tmpl > databricks.yml RENAMED_VOLUME="main.test-schema1-renamed-${UNIQUE_NAME}.myvolume" NEW_VOLUME="main.test-schema2-${UNIQUE_NAME}.myvolume" +RENAMED_MODEL="main.test-schema1-renamed-${UNIQUE_NAME}.mymodel" +NEW_MODEL="main.test-schema2-${UNIQUE_NAME}.mymodel" cleanup() { trace $CLI bundle destroy --auto-approve @@ -11,24 +13,27 @@ cleanup() { } trap cleanup EXIT -title "Deploy two schemas and a volume in the first one" +title "Deploy two schemas, and a volume and a registered model in the first one" trace $CLI bundle deploy print_requests.py //unity-catalog &> LOG.deploy_requests add_repl "$($CLI volumes read "main.test-schema1-${UNIQUE_NAME}.myvolume" | jq -r .volume_id)" OLD_VOLUME_ID -title "Rename the first schema and move the volume to the second one in one deploy. Moving the volume recreates it" +title "Rename the first schema and move the volume and the model to the second one in one deploy. Moving them recreates them" trace update_file.py databricks.yml test-schema1- test-schema1-renamed- trace update_file.py databricks.yml schemas.schema1.name schemas.schema2.name # Drop the remote_state fields that differ between clouds or from the test server. trace $CLI bundle plan --output json | tee .databricks/plan.json | jq .plan | normalize_uc_payload.py created_at updated_at updated_by metastore_id effective_predictive_optimization_flag storage_location trace $CLI bundle deploy $(readplanarg .databricks/plan.json) --auto-approve -trace print_requests.py //unity-catalog +# The volume and the model are recreated in parallel. +trace print_requests.py --sort //unity-catalog -title "The volume is in the second schema" +title "The volume and the model are in the second schema" trace $CLI volumes read "$NEW_VOLUME" | jq '{full_name}' +trace $CLI registered-models get "$NEW_MODEL" | jq '{full_name}' -title "The old volume, moved with the renamed schema, was deleted there" +title "The old volume and model, moved with the renamed schema, were deleted there" trace musterr $CLI volumes read "$RENAMED_VOLUME" +trace musterr $CLI registered-models get "$RENAMED_MODEL" title "Redeploy is a no-op" trace $CLI bundle plan From 404bbc7c4f2d5eedf60bedd051808eb08074a0db Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 14:09:00 +0100 Subject: [PATCH 18/44] acc: a job reading a registered model's full_name and id follows its schema's rename Co-authored-by: Isaac --- .../databricks.yml.tmpl | 9 +++++ .../schemas/rename_with_volume_ref/output.txt | 34 ++++++++++++++----- .../schemas/rename_with_volume_ref/script | 6 ++-- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/acceptance/bundle/resources/schemas/rename_with_volume_ref/databricks.yml.tmpl b/acceptance/bundle/resources/schemas/rename_with_volume_ref/databricks.yml.tmpl index bddda4baff0..594c0bed4ef 100644 --- a/acceptance/bundle/resources/schemas/rename_with_volume_ref/databricks.yml.tmpl +++ b/acceptance/bundle/resources/schemas/rename_with_volume_ref/databricks.yml.tmpl @@ -11,6 +11,11 @@ resources: catalog_name: main schema_name: ${resources.schemas.schema1.name} name: myvolume + registered_models: + model1: + catalog_name: main + schema_name: ${resources.schemas.schema1.name} + name: mymodel jobs: job1: name: test-job-$UNIQUE_NAME @@ -21,3 +26,7 @@ resources: default: ${resources.volumes.volume1.id} - name: volume_uuid default: ${resources.volumes.volume1.volume_id} + - name: model_full_name + default: ${resources.registered_models.model1.full_name} + - name: model_id + default: ${resources.registered_models.model1.id} diff --git a/acceptance/bundle/resources/schemas/rename_with_volume_ref/output.txt b/acceptance/bundle/resources/schemas/rename_with_volume_ref/output.txt index f9ee1f48e1c..09486d4df27 100644 --- a/acceptance/bundle/resources/schemas/rename_with_volume_ref/output.txt +++ b/acceptance/bundle/resources/schemas/rename_with_volume_ref/output.txt @@ -1,13 +1,14 @@ -=== Deploy a schema, a volume in it and a job that reads the volume's full_name and id +=== Deploy a schema, a volume and a registered model in it, and a job that reads their full_name and id >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Created jobs.job1 +Created registered_models.model1 Created schemas.schema1 Created volumes.volume1 Files: 2 uploaded, 0 deleted -Resources: 3 created, 0 changed, 0 deleted, 0 unchanged +Resources: 4 created, 0 changed, 0 deleted, 0 unchanged >>> [CLI] jobs get [JOB_ID] [ @@ -22,6 +23,14 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged { "default": "[VOLUME_ID]", "name": "volume_uuid" + }, + { + "default": "main.test-schema-[UNIQUE_NAME].mymodel", + "name": "model_full_name" + }, + { + "default": "main.test-schema-[UNIQUE_NAME].mymodel", + "name": "model_id" } ] @@ -29,22 +38,22 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged >>> update_file.py databricks.yml test-schema- test-schema-renamed- -=== The volume's full_name and id change with the schema, so the job is updated too +=== The full_name and id of the volume and the model change with the schema, so the job is updated too >>> [CLI] bundle plan update jobs.job1 update schemas.schema1 -Plan: 0 to add, 2 to change, 0 to delete, 1 unchanged +Plan: 0 to add, 2 to change, 0 to delete, 2 unchanged -=== Deploy passes the volume's new full_name and id to the job +=== Deploy passes the new full_name and id of the volume and the model to the job >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Updated jobs.job1 Updated schemas.schema1 Files: 2 uploaded, 0 deleted -Resources: 0 created, 2 changed, 0 deleted, 1 unchanged +Resources: 0 created, 2 changed, 0 deleted, 2 unchanged >>> print_requests.py //unity-catalog { @@ -70,17 +79,26 @@ Resources: 0 created, 2 changed, 0 deleted, 1 unchanged { "default": "[VOLUME_ID]", "name": "volume_uuid" + }, + { + "default": "main.test-schema-renamed-[UNIQUE_NAME].mymodel", + "name": "model_full_name" + }, + { + "default": "main.test-schema-renamed-[UNIQUE_NAME].mymodel", + "name": "model_id" } ] === Redeploy is a no-op >>> [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged +Plan: 0 to add, 0 to change, 0 to delete, 4 unchanged >>> [CLI] bundle destroy --auto-approve The following resources will be deleted: delete resources.jobs.job1 + delete resources.registered_models.model1 delete resources.schemas.schema1 delete resources.volumes.volume1 @@ -95,4 +113,4 @@ is removed from the catalog, but the underlying files are not deleted: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default -Destroy: 3 deleted +Destroy: 4 deleted diff --git a/acceptance/bundle/resources/schemas/rename_with_volume_ref/script b/acceptance/bundle/resources/schemas/rename_with_volume_ref/script index 6418f29011d..dbaaf812709 100644 --- a/acceptance/bundle/resources/schemas/rename_with_volume_ref/script +++ b/acceptance/bundle/resources/schemas/rename_with_volume_ref/script @@ -8,7 +8,7 @@ cleanup() { } trap cleanup EXIT -title "Deploy a schema, a volume in it and a job that reads the volume's full_name and id" +title "Deploy a schema, a volume and a registered model in it, and a job that reads their full_name and id" trace $CLI bundle deploy print_requests.py //unity-catalog &> LOG.deploy_requests JOB_ID=$($CLI bundle summary --output json | jq -r .resources.jobs.job1.id) @@ -19,10 +19,10 @@ trace $CLI jobs get "$JOB_ID" | jq .settings.parameters title "Rename the schema" trace update_file.py databricks.yml test-schema- test-schema-renamed- -title "The volume's full_name and id change with the schema, so the job is updated too" +title "The full_name and id of the volume and the model change with the schema, so the job is updated too" trace $CLI bundle plan -title "Deploy passes the volume's new full_name and id to the job" +title "Deploy passes the new full_name and id of the volume and the model to the job" trace $CLI bundle deploy trace print_requests.py //unity-catalog trace $CLI jobs get "$JOB_ID" | jq .settings.parameters From a285fd1ecda2e020264e3f91c0a20ac32b484bc7 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 14:09:00 +0100 Subject: [PATCH 19/44] acc: grants follow a registered model's in-place rename Co-authored-by: Isaac --- .../volume_change_name/databricks.yml.tmpl | 9 ++ .../grants/volume_change_name/output.txt | 135 ++++++++++++++---- .../grants/volume_change_name/script | 18 ++- 3 files changed, 132 insertions(+), 30 deletions(-) diff --git a/acceptance/bundle/resources/grants/volume_change_name/databricks.yml.tmpl b/acceptance/bundle/resources/grants/volume_change_name/databricks.yml.tmpl index a8c9a407fda..dddb7d5229f 100644 --- a/acceptance/bundle/resources/grants/volume_change_name/databricks.yml.tmpl +++ b/acceptance/bundle/resources/grants/volume_change_name/databricks.yml.tmpl @@ -15,3 +15,12 @@ resources: - principal: deco-test-user@databricks.com privileges: - READ_VOLUME + registered_models: + model1: + catalog_name: main + schema_name: ${resources.schemas.schema1.name} + name: mymodel + grants: + - principal: deco-test-user@databricks.com + privileges: + - APPLY_TAG diff --git a/acceptance/bundle/resources/grants/volume_change_name/output.txt b/acceptance/bundle/resources/grants/volume_change_name/output.txt index 8537be1c256..b7e8405ce04 100644 --- a/acceptance/bundle/resources/grants/volume_change_name/output.txt +++ b/acceptance/bundle/resources/grants/volume_change_name/output.txt @@ -1,31 +1,32 @@ -=== Deploy a volume with grants +=== Deploy a volume and a registered model with grants >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Created registered_models.model1 +Created registered_models.model1.grants Created schemas.schema1 Created volumes.volume1 Created volumes.volume1.grants Files: 2 uploaded, 0 deleted -Resources: 3 created, 0 changed, 0 deleted, 0 unchanged +Resources: 5 created, 0 changed, 0 deleted, 0 unchanged ->>> print_requests.py //unity-catalog +>>> print_requests.py --sort //unity-catalog { - "method": "POST", - "path": "/api/2.1/unity-catalog/schemas", - "body": { - "catalog_name": "main", - "name": "test-schema-[UNIQUE_NAME]" - } -} -{ - "method": "POST", - "path": "/api/2.1/unity-catalog/volumes", + "method": "PATCH", + "path": "/api/2.1/unity-catalog/permissions/function/main.test-schema-[UNIQUE_NAME].mymodel", "body": { - "catalog_name": "main", - "name": "myvolume", - "schema_name": "test-schema-[UNIQUE_NAME]", - "volume_type": "MANAGED" + "changes": [ + { + "add": [ + "APPLY_TAG" + ], + "principal": "deco-test-user@databricks.com", + "remove": [ + "ALL_PRIVILEGES" + ] + } + ] } } { @@ -45,14 +46,46 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged ] } } +{ + "method": "POST", + "path": "/api/2.1/unity-catalog/models", + "body": { + "catalog_name": "main", + "name": "mymodel", + "schema_name": "test-schema-[UNIQUE_NAME]" + } +} +{ + "method": "POST", + "path": "/api/2.1/unity-catalog/schemas", + "body": { + "catalog_name": "main", + "name": "test-schema-[UNIQUE_NAME]" + } +} +{ + "method": "POST", + "path": "/api/2.1/unity-catalog/volumes", + "body": { + "catalog_name": "main", + "name": "myvolume", + "schema_name": "test-schema-[UNIQUE_NAME]", + "volume_type": "MANAGED" + } +} >>> read_state.py volumes volume1.grants id volumes volume1.grants id='volume/main.test-schema-[UNIQUE_NAME].myvolume' -=== Rename the volume: its ID changes, and so does the ID of its grants +>>> read_state.py registered_models model1.grants id +registered_models model1.grants id='function/main.test-schema-[UNIQUE_NAME].mymodel' + +=== Rename the volume and the model: their IDs change, and so do the IDs of their grants >>> update_file.py databricks.yml myvolume myvolume_renamed +>>> update_file.py databricks.yml mymodel mymodel_renamed + >>> [CLI] bundle plan --output json { "full_name": { @@ -64,22 +97,54 @@ volumes volume1.grants id='volume/main.test-schema-[UNIQUE_NAME].myvolume' } } -=== Deploy renames the volume and applies the grants under the new name +>>> [CLI] bundle plan --output json +{ + "full_name": { + "action": "update_id", + "reason": "id_changes", + "old": "main.test-schema-[UNIQUE_NAME].mymodel", + "new": "", + "remote": "main.test-schema-[UNIQUE_NAME].mymodel" + } +} + +=== Deploy renames the volume and the model in place and applies the grants under the new names >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Updated registered_models.model1 +Updated registered_models.model1.grants Updated volumes.volume1 Updated volumes.volume1.grants Files: 1 uploaded, 0 deleted -Resources: 0 created, 2 changed, 0 deleted, 1 unchanged +Resources: 0 created, 4 changed, 0 deleted, 1 unchanged ->>> print_requests.py //unity-catalog +>>> print_requests.py --sort //unity-catalog { "method": "PATCH", - "path": "/api/2.1/unity-catalog/volumes/main.test-schema-[UNIQUE_NAME].myvolume", + "path": "/api/2.1/unity-catalog/models/main.test-schema-[UNIQUE_NAME].mymodel", "body": { + "catalog_name": "main", "comment": "", - "new_name": "myvolume_renamed" + "new_name": "mymodel_renamed", + "schema_name": "test-schema-[UNIQUE_NAME]" + } +} +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/permissions/function/main.test-schema-[UNIQUE_NAME].mymodel_renamed", + "body": { + "changes": [ + { + "add": [ + "APPLY_TAG" + ], + "principal": "deco-test-user@databricks.com", + "remove": [ + "ALL_PRIVILEGES" + ] + } + ] } } { @@ -99,6 +164,14 @@ Resources: 0 created, 2 changed, 0 deleted, 1 unchanged ] } } +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/volumes/main.test-schema-[UNIQUE_NAME].myvolume", + "body": { + "comment": "", + "new_name": "myvolume_renamed" + } +} >>> [CLI] grants get volume main.test-schema-[UNIQUE_NAME].myvolume_renamed { @@ -108,16 +181,28 @@ Resources: 0 created, 2 changed, 0 deleted, 1 unchanged ] } +>>> [CLI] grants get function main.test-schema-[UNIQUE_NAME].mymodel_renamed +{ + "principal": "deco-test-user@databricks.com", + "privileges": [ + "APPLY_TAG" + ] +} + === The grants are recorded under the new name, so the next plan is a no-op >>> read_state.py volumes volume1.grants id volumes volume1.grants id='volume/main.test-schema-[UNIQUE_NAME].myvolume_renamed' +>>> read_state.py registered_models model1.grants id +registered_models model1.grants id='function/main.test-schema-[UNIQUE_NAME].mymodel_renamed' + >>> [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged +Plan: 0 to add, 0 to change, 0 to delete, 5 unchanged >>> [CLI] bundle destroy --auto-approve The following resources will be deleted: + delete resources.registered_models.model1 delete resources.schemas.schema1 delete resources.volumes.volume1 @@ -132,4 +217,4 @@ is removed from the catalog, but the underlying files are not deleted: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default -Destroy: 2 deleted +Destroy: 3 deleted diff --git a/acceptance/bundle/resources/grants/volume_change_name/script b/acceptance/bundle/resources/grants/volume_change_name/script index 3ae81092846..21ce12a9c41 100644 --- a/acceptance/bundle/resources/grants/volume_change_name/script +++ b/acceptance/bundle/resources/grants/volume_change_name/script @@ -1,6 +1,7 @@ envsubst < databricks.yml.tmpl > databricks.yml NEW_VOLUME="main.test-schema-${UNIQUE_NAME}.myvolume_renamed" +NEW_MODEL="main.test-schema-${UNIQUE_NAME}.mymodel_renamed" cleanup() { trace $CLI bundle destroy --auto-approve @@ -10,20 +11,27 @@ cleanup() { } trap cleanup EXIT -title "Deploy a volume with grants" +title "Deploy a volume and a registered model with grants" trace $CLI bundle deploy -trace print_requests.py //unity-catalog +# The volume and the model, and then their grants, are changed in parallel. +trace print_requests.py --sort //unity-catalog trace read_state.py volumes volume1.grants id +trace read_state.py registered_models model1.grants id -title "Rename the volume: its ID changes, and so does the ID of its grants" +title "Rename the volume and the model: their IDs change, and so do the IDs of their grants" trace update_file.py databricks.yml myvolume myvolume_renamed +trace update_file.py databricks.yml mymodel mymodel_renamed trace $CLI bundle plan --output json | jq '.plan["resources.volumes.volume1.grants"].changes' +trace $CLI bundle plan --output json | jq '.plan["resources.registered_models.model1.grants"].changes' -title "Deploy renames the volume and applies the grants under the new name" +title "Deploy renames the volume and the model in place and applies the grants under the new names" trace $CLI bundle deploy -trace print_requests.py //unity-catalog +# The volume and the model, and then their grants, are changed in parallel. +trace print_requests.py --sort //unity-catalog trace $CLI grants get volume "$NEW_VOLUME" | jq '.privilege_assignments[] | select(.principal == "deco-test-user@databricks.com")' +trace $CLI grants get function "$NEW_MODEL" | jq '.privilege_assignments[] | select(.principal == "deco-test-user@databricks.com")' title "The grants are recorded under the new name, so the next plan is a no-op" trace read_state.py volumes volume1.grants id +trace read_state.py registered_models model1.grants id trace $CLI bundle plan From 454d9d2dbc1dc6abb43b268425d7a46ee3d6bb31 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 14:33:34 +0100 Subject: [PATCH 20/44] acc: keep volumes/rename_catalog_and_schema about volumes; the model case moves to registered_models/ Co-authored-by: Isaac --- .../databricks.yml.tmpl | 5 -- .../rename_catalog_and_schema/output.txt | 90 +++---------------- .../volumes/rename_catalog_and_schema/script | 12 ++- 3 files changed, 16 insertions(+), 91 deletions(-) diff --git a/acceptance/bundle/resources/volumes/rename_catalog_and_schema/databricks.yml.tmpl b/acceptance/bundle/resources/volumes/rename_catalog_and_schema/databricks.yml.tmpl index 37a21cc13da..e45eccddc44 100644 --- a/acceptance/bundle/resources/volumes/rename_catalog_and_schema/databricks.yml.tmpl +++ b/acceptance/bundle/resources/volumes/rename_catalog_and_schema/databricks.yml.tmpl @@ -14,8 +14,3 @@ resources: catalog_name: ${resources.catalogs.catalog1.name} schema_name: ${resources.schemas.schema1.name} name: myvolume - registered_models: - model1: - catalog_name: ${resources.catalogs.catalog1.name} - schema_name: ${resources.schemas.schema1.name} - name: mymodel diff --git a/acceptance/bundle/resources/volumes/rename_catalog_and_schema/output.txt b/acceptance/bundle/resources/volumes/rename_catalog_and_schema/output.txt index 3f62d48457a..f5d7df1a699 100644 --- a/acceptance/bundle/resources/volumes/rename_catalog_and_schema/output.txt +++ b/acceptance/bundle/resources/volumes/rename_catalog_and_schema/output.txt @@ -1,14 +1,13 @@ -=== Deploy a catalog with a schema, a volume and a registered model in it +=== Deploy a catalog with a schema and a volume in it >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Created catalogs.catalog1 -Created registered_models.model1 Created schemas.schema1 Created volumes.volume1 Files: 2 uploaded, 0 deleted -Resources: 4 created, 0 changed, 0 deleted, 0 unchanged +Resources: 3 created, 0 changed, 0 deleted, 0 unchanged === Rename the catalog and the schema in one deploy @@ -16,7 +15,7 @@ Resources: 4 created, 0 changed, 0 deleted, 0 unchanged >>> update_file.py databricks.yml name: myschema name: myschema2 -=== Both parents of the volume and the model are renamed, so both their catalog_name and schema_name follow them +=== Both of the volume's parents are renamed, so both its catalog_name and schema_name follow them >>> [CLI] bundle plan --output json { @@ -29,6 +28,7 @@ Resources: 4 created, 0 changed, 0 deleted, 0 unchanged }, "remote_state": { "catalog_type": "MANAGED_CATALOG", + "created_at": [UNIX_TIME_MILLIS][0], "created_by": "[USERNAME]", "full_name": "test_catalog_[UNIQUE_NAME]", "name": "test_catalog_[UNIQUE_NAME]", @@ -44,66 +44,6 @@ Resources: 4 created, 0 changed, 0 deleted, 0 unchanged } } }, - "resources.registered_models.model1": { - "depends_on": [ - { - "node": "resources.catalogs.catalog1", - "label": "${resources.catalogs.catalog1.name}" - }, - { - "node": "resources.schemas.schema1", - "label": "${resources.schemas.schema1.name}" - } - ], - "action": "update_id", - "state_only": true, - "new_state": { - "value": { - "catalog_name": "test_catalog_renamed_[UNIQUE_NAME]", - "name": "mymodel", - "schema_name": "myschema2" - } - }, - "remote_state": { - "catalog_name": "test_catalog_[UNIQUE_NAME]", - "created_by": "[USERNAME]", - "full_name": "test_catalog_[UNIQUE_NAME].myschema.mymodel", - "name": "mymodel", - "owner": "[USERNAME]", - "schema_name": "myschema" - }, - "changes": { - "catalog_name": { - "action": "update_id", - "reason": "parent_renamed", - "old": "test_catalog_[UNIQUE_NAME]", - "new": "test_catalog_renamed_[UNIQUE_NAME]", - "remote": "test_catalog_[UNIQUE_NAME]" - }, - "created_by": { - "action": "skip", - "reason": "output_only", - "remote": "[USERNAME]" - }, - "full_name": { - "action": "skip", - "reason": "backend_default", - "remote": "test_catalog_[UNIQUE_NAME].myschema.mymodel" - }, - "owner": { - "action": "skip", - "reason": "backend_default", - "remote": "[USERNAME]" - }, - "schema_name": { - "action": "update_id", - "reason": "parent_renamed", - "old": "myschema", - "new": "myschema2", - "remote": "myschema" - } - } - }, "resources.schemas.schema1": { "depends_on": [ { @@ -121,6 +61,7 @@ Resources: 4 created, 0 changed, 0 deleted, 0 unchanged "remote_state": { "catalog_name": "test_catalog_[UNIQUE_NAME]", "catalog_type": "MANAGED_CATALOG", + "created_at": [UNIX_TIME_MILLIS][1], "created_by": "[USERNAME]", "full_name": "test_catalog_[UNIQUE_NAME].myschema", "name": "myschema", @@ -173,6 +114,7 @@ Resources: 4 created, 0 changed, 0 deleted, 0 unchanged }, "remote_state": { "catalog_name": "test_catalog_[UNIQUE_NAME]", + "created_at": [UNIX_TIME_MILLIS][2], "created_by": "[USERNAME]", "full_name": "test_catalog_[UNIQUE_NAME].myschema.myvolume", "name": "myvolume", @@ -206,14 +148,14 @@ Resources: 4 created, 0 changed, 0 deleted, 0 unchanged } } -=== Deploy renames the catalog, then the schema under it. UC moves the volume and the model both times, so they get no request +=== Deploy renames the catalog, then the schema under it. UC moves the volume both times, so it gets no request >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Updated catalogs.catalog1 Updated schemas.schema1 Files: 2 uploaded, 0 deleted -Resources: 0 created, 2 changed, 0 deleted, 2 unchanged +Resources: 0 created, 2 changed, 0 deleted, 1 unchanged >>> print_requests.py //unity-catalog { @@ -235,7 +177,7 @@ Resources: 0 created, 2 changed, 0 deleted, 2 unchanged } } -=== The schema, the volume and the model are under the new names, not recreated +=== The schema and the volume are under the new names, with their original ids >>> [CLI] schemas get test_catalog_renamed_[UNIQUE_NAME].myschema2 { @@ -249,20 +191,11 @@ Resources: 0 created, 2 changed, 0 deleted, 2 unchanged "volume_id": "[VOLUME_ID]" } ->>> [CLI] registered-models get test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel -{ - "full_name": "test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel", - "created_at": [MODEL_CREATED_AT] -} - >>> [CLI] bundle summary --output json { "catalogs": { "catalog1": "test_catalog_renamed_[UNIQUE_NAME]" }, - "registered_models": { - "model1": "test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel" - }, "schemas": { "schema1": "test_catalog_renamed_[UNIQUE_NAME].myschema2" }, @@ -274,12 +207,11 @@ Resources: 0 created, 2 changed, 0 deleted, 2 unchanged === Redeploy is a no-op >>> [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 4 unchanged +Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged >>> [CLI] bundle destroy --auto-approve The following resources will be deleted: delete resources.catalogs.catalog1 - delete resources.registered_models.model1 delete resources.schemas.schema1 delete resources.volumes.volume1 @@ -294,4 +226,4 @@ is removed from the catalog, but the underlying files are not deleted: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default -Destroy: 4 deleted +Destroy: 3 deleted diff --git a/acceptance/bundle/resources/volumes/rename_catalog_and_schema/script b/acceptance/bundle/resources/volumes/rename_catalog_and_schema/script index 5a1f553ab7b..2f0b71af10b 100644 --- a/acceptance/bundle/resources/volumes/rename_catalog_and_schema/script +++ b/acceptance/bundle/resources/volumes/rename_catalog_and_schema/script @@ -10,29 +10,27 @@ cleanup() { } trap cleanup EXIT -title "Deploy a catalog with a schema, a volume and a registered model in it" +title "Deploy a catalog with a schema and a volume in it" trace $CLI bundle deploy print_requests.py //unity-catalog &> LOG.deploy_requests add_repl "$($CLI schemas get "test_catalog_${UNIQUE_NAME}.myschema" | jq -r .schema_id)" SCHEMA_ID add_repl "$($CLI volumes read "test_catalog_${UNIQUE_NAME}.myschema.myvolume" | jq -r .volume_id)" VOLUME_ID -add_repl "$($CLI registered-models get "test_catalog_${UNIQUE_NAME}.myschema.mymodel" | jq -r .created_at)" MODEL_CREATED_AT title "Rename the catalog and the schema in one deploy" trace update_file.py databricks.yml test_catalog_ test_catalog_renamed_ trace update_file.py databricks.yml "name: myschema" "name: myschema2" -title "Both parents of the volume and the model are renamed, so both their catalog_name and schema_name follow them" +title "Both of the volume's parents are renamed, so both its catalog_name and schema_name follow them" # Drop the remote_state fields that differ between clouds or from the test server. -trace $CLI bundle plan --output json | tee .databricks/plan.json | jq .plan | normalize_uc_payload.py created_at updated_at updated_by metastore_id browse_only effective_predictive_optimization_flag enable_predictive_optimization isolation_mode securable_type storage_location +trace $CLI bundle plan --output json | tee .databricks/plan.json | jq .plan | normalize_uc_payload.py updated_at updated_by metastore_id browse_only effective_predictive_optimization_flag enable_predictive_optimization isolation_mode securable_type storage_location -title "Deploy renames the catalog, then the schema under it. UC moves the volume and the model both times, so they get no request" +title "Deploy renames the catalog, then the schema under it. UC moves the volume both times, so it gets no request" trace $CLI bundle deploy $(readplanarg .databricks/plan.json) trace print_requests.py //unity-catalog -title "The schema, the volume and the model are under the new names, not recreated" +title "The schema and the volume are under the new names, with their original ids" trace $CLI schemas get "$NEW_SCHEMA" | jq '{full_name, schema_id}' trace $CLI volumes read "$NEW_SCHEMA.myvolume" | jq '{full_name, volume_id}' -trace $CLI registered-models get "$NEW_SCHEMA.mymodel" | jq '{full_name, created_at}' trace $CLI bundle summary --output json | jq '.resources | map_values(map_values(.id))' title "Redeploy is a no-op" From d4afb6d342f334279e0e52f45be6fba6a80b50b6 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 14:33:35 +0100 Subject: [PATCH 21/44] acc: keep volumes/move_from_renamed_schema about volumes; the model case moves to registered_models/ Co-authored-by: Isaac --- .../databricks.yml.tmpl | 5 - .../move_from_renamed_schema/output.txt | 99 +++---------------- .../volumes/move_from_renamed_schema/script | 15 +-- 3 files changed, 16 insertions(+), 103 deletions(-) diff --git a/acceptance/bundle/resources/volumes/move_from_renamed_schema/databricks.yml.tmpl b/acceptance/bundle/resources/volumes/move_from_renamed_schema/databricks.yml.tmpl index 8f4fb91631a..01d93162314 100644 --- a/acceptance/bundle/resources/volumes/move_from_renamed_schema/databricks.yml.tmpl +++ b/acceptance/bundle/resources/volumes/move_from_renamed_schema/databricks.yml.tmpl @@ -14,8 +14,3 @@ resources: catalog_name: main schema_name: ${resources.schemas.schema1.name} name: myvolume - registered_models: - model1: - catalog_name: main - schema_name: ${resources.schemas.schema1.name} - name: mymodel diff --git a/acceptance/bundle/resources/volumes/move_from_renamed_schema/output.txt b/acceptance/bundle/resources/volumes/move_from_renamed_schema/output.txt index 844eacac5c4..c265ef49c8d 100644 --- a/acceptance/bundle/resources/volumes/move_from_renamed_schema/output.txt +++ b/acceptance/bundle/resources/volumes/move_from_renamed_schema/output.txt @@ -1,16 +1,15 @@ -=== Deploy two schemas, and a volume and a registered model in the first one +=== Deploy two schemas and a volume in the first one >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... -Created registered_models.model1 Created schemas.schema1 Created schemas.schema2 Created volumes.volume1 Files: 2 uploaded, 0 deleted -Resources: 4 created, 0 changed, 0 deleted, 0 unchanged +Resources: 3 created, 0 changed, 0 deleted, 0 unchanged -=== Rename the first schema and move the volume and the model to the second one in one deploy. Moving them recreates them +=== Rename the first schema and move the volume to the second one in one deploy. Moving the volume recreates it >>> update_file.py databricks.yml test-schema1- test-schema1-renamed- @@ -18,59 +17,6 @@ Resources: 4 created, 0 changed, 0 deleted, 0 unchanged >>> [CLI] bundle plan --output json { - "resources.registered_models.model1": { - "id": "main.test-schema1-renamed-[UNIQUE_NAME].mymodel", - "depends_on": [ - { - "node": "resources.schemas.schema2", - "label": "${resources.schemas.schema2.name}" - }, - { - "node": "resources.schemas.schema1", - "label": "${resources.schemas.schema1.name}" - } - ], - "action": "recreate", - "new_state": { - "value": { - "catalog_name": "main", - "name": "mymodel", - "schema_name": "test-schema2-[UNIQUE_NAME]" - } - }, - "remote_state": { - "catalog_name": "main", - "created_by": "[USERNAME]", - "full_name": "main.test-schema1-[UNIQUE_NAME].mymodel", - "name": "mymodel", - "owner": "[USERNAME]", - "schema_name": "test-schema1-[UNIQUE_NAME]" - }, - "changes": { - "created_by": { - "action": "skip", - "reason": "output_only", - "remote": "[USERNAME]" - }, - "full_name": { - "action": "skip", - "reason": "backend_default", - "remote": "main.test-schema1-[UNIQUE_NAME].mymodel" - }, - "owner": { - "action": "skip", - "reason": "backend_default", - "remote": "[USERNAME]" - }, - "schema_name": { - "action": "recreate", - "reason": "id_field", - "old": "test-schema1-[UNIQUE_NAME]", - "new": "test-schema2-[UNIQUE_NAME]", - "remote": "test-schema1-[UNIQUE_NAME]" - } - } - }, "resources.schemas.schema1": { "action": "update_id", "new_state": { @@ -185,21 +131,12 @@ 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: recreate resources.volumes.volume1 -Recreated registered_models.model1 Recreated volumes.volume1 Updated schemas.schema1 Files: 2 uploaded, 0 deleted -Resources: 2 created, 1 changed, 2 deleted, 1 unchanged +Resources: 1 created, 1 changed, 1 deleted, 1 unchanged ->>> print_requests.py --sort //unity-catalog -{ - "method": "DELETE", - "path": "/api/2.1/unity-catalog/models/main.test-schema1-renamed-[UNIQUE_NAME].mymodel" -} -{ - "method": "DELETE", - "path": "/api/2.1/unity-catalog/volumes/main.test-schema1-renamed-[UNIQUE_NAME].myvolume" -} +>>> print_requests.py //unity-catalog { "method": "PATCH", "path": "/api/2.1/unity-catalog/schemas/main.test-schema1-[UNIQUE_NAME]", @@ -210,13 +147,8 @@ Resources: 2 created, 1 changed, 2 deleted, 1 unchanged } } { - "method": "POST", - "path": "/api/2.1/unity-catalog/models", - "body": { - "catalog_name": "main", - "name": "mymodel", - "schema_name": "test-schema2-[UNIQUE_NAME]" - } + "method": "DELETE", + "path": "/api/2.1/unity-catalog/volumes/main.test-schema1-renamed-[UNIQUE_NAME].myvolume" } { "method": "POST", @@ -229,34 +161,25 @@ Resources: 2 created, 1 changed, 2 deleted, 1 unchanged } } -=== The volume and the model are in the second schema +=== The volume is in the second schema >>> [CLI] volumes read main.test-schema2-[UNIQUE_NAME].myvolume { "full_name": "main.test-schema2-[UNIQUE_NAME].myvolume" } ->>> [CLI] registered-models get main.test-schema2-[UNIQUE_NAME].mymodel -{ - "full_name": "main.test-schema2-[UNIQUE_NAME].mymodel" -} - -=== The old volume and model, moved with the renamed schema, were deleted there +=== The old volume, moved with the renamed schema, was deleted there >>> musterr [CLI] volumes read main.test-schema1-renamed-[UNIQUE_NAME].myvolume Error: Volume 'main.test-schema1-renamed-[UNIQUE_NAME].myvolume' does not exist. ->>> musterr [CLI] registered-models get main.test-schema1-renamed-[UNIQUE_NAME].mymodel -Error: Routine or Model 'main.test-schema1-renamed-[UNIQUE_NAME].mymodel' does not exist. - === Redeploy is a no-op >>> [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 4 unchanged +Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged >>> [CLI] bundle destroy --auto-approve The following resources will be deleted: - delete resources.registered_models.model1 delete resources.schemas.schema1 delete resources.schemas.schema2 delete resources.volumes.volume1 @@ -273,4 +196,4 @@ is removed from the catalog, but the underlying files are not deleted: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default -Destroy: 4 deleted +Destroy: 3 deleted diff --git a/acceptance/bundle/resources/volumes/move_from_renamed_schema/script b/acceptance/bundle/resources/volumes/move_from_renamed_schema/script index 9e6284c4726..5d038da5e21 100644 --- a/acceptance/bundle/resources/volumes/move_from_renamed_schema/script +++ b/acceptance/bundle/resources/volumes/move_from_renamed_schema/script @@ -2,8 +2,6 @@ envsubst < databricks.yml.tmpl > databricks.yml RENAMED_VOLUME="main.test-schema1-renamed-${UNIQUE_NAME}.myvolume" NEW_VOLUME="main.test-schema2-${UNIQUE_NAME}.myvolume" -RENAMED_MODEL="main.test-schema1-renamed-${UNIQUE_NAME}.mymodel" -NEW_MODEL="main.test-schema2-${UNIQUE_NAME}.mymodel" cleanup() { trace $CLI bundle destroy --auto-approve @@ -13,27 +11,24 @@ cleanup() { } trap cleanup EXIT -title "Deploy two schemas, and a volume and a registered model in the first one" +title "Deploy two schemas and a volume in the first one" trace $CLI bundle deploy print_requests.py //unity-catalog &> LOG.deploy_requests add_repl "$($CLI volumes read "main.test-schema1-${UNIQUE_NAME}.myvolume" | jq -r .volume_id)" OLD_VOLUME_ID -title "Rename the first schema and move the volume and the model to the second one in one deploy. Moving them recreates them" +title "Rename the first schema and move the volume to the second one in one deploy. Moving the volume recreates it" trace update_file.py databricks.yml test-schema1- test-schema1-renamed- trace update_file.py databricks.yml schemas.schema1.name schemas.schema2.name # Drop the remote_state fields that differ between clouds or from the test server. trace $CLI bundle plan --output json | tee .databricks/plan.json | jq .plan | normalize_uc_payload.py created_at updated_at updated_by metastore_id effective_predictive_optimization_flag storage_location trace $CLI bundle deploy $(readplanarg .databricks/plan.json) --auto-approve -# The volume and the model are recreated in parallel. -trace print_requests.py --sort //unity-catalog +trace print_requests.py //unity-catalog -title "The volume and the model are in the second schema" +title "The volume is in the second schema" trace $CLI volumes read "$NEW_VOLUME" | jq '{full_name}' -trace $CLI registered-models get "$NEW_MODEL" | jq '{full_name}' -title "The old volume and model, moved with the renamed schema, were deleted there" +title "The old volume, moved with the renamed schema, was deleted there" trace musterr $CLI volumes read "$RENAMED_VOLUME" -trace musterr $CLI registered-models get "$RENAMED_MODEL" title "Redeploy is a no-op" trace $CLI bundle plan From 89b9a7990b16b7feedeac82527c3a126d70e2074 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 14:33:37 +0100 Subject: [PATCH 22/44] acc: keep schemas/rename_with_volume_ref about the volume Co-authored-by: Isaac --- .../databricks.yml.tmpl | 9 ----- .../schemas/rename_with_volume_ref/output.txt | 34 +++++-------------- .../schemas/rename_with_volume_ref/script | 6 ++-- 3 files changed, 11 insertions(+), 38 deletions(-) diff --git a/acceptance/bundle/resources/schemas/rename_with_volume_ref/databricks.yml.tmpl b/acceptance/bundle/resources/schemas/rename_with_volume_ref/databricks.yml.tmpl index 594c0bed4ef..bddda4baff0 100644 --- a/acceptance/bundle/resources/schemas/rename_with_volume_ref/databricks.yml.tmpl +++ b/acceptance/bundle/resources/schemas/rename_with_volume_ref/databricks.yml.tmpl @@ -11,11 +11,6 @@ resources: catalog_name: main schema_name: ${resources.schemas.schema1.name} name: myvolume - registered_models: - model1: - catalog_name: main - schema_name: ${resources.schemas.schema1.name} - name: mymodel jobs: job1: name: test-job-$UNIQUE_NAME @@ -26,7 +21,3 @@ resources: default: ${resources.volumes.volume1.id} - name: volume_uuid default: ${resources.volumes.volume1.volume_id} - - name: model_full_name - default: ${resources.registered_models.model1.full_name} - - name: model_id - default: ${resources.registered_models.model1.id} diff --git a/acceptance/bundle/resources/schemas/rename_with_volume_ref/output.txt b/acceptance/bundle/resources/schemas/rename_with_volume_ref/output.txt index 09486d4df27..f9ee1f48e1c 100644 --- a/acceptance/bundle/resources/schemas/rename_with_volume_ref/output.txt +++ b/acceptance/bundle/resources/schemas/rename_with_volume_ref/output.txt @@ -1,14 +1,13 @@ -=== Deploy a schema, a volume and a registered model in it, and a job that reads their full_name and id +=== Deploy a schema, a volume in it and a job that reads the volume's full_name and id >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Created jobs.job1 -Created registered_models.model1 Created schemas.schema1 Created volumes.volume1 Files: 2 uploaded, 0 deleted -Resources: 4 created, 0 changed, 0 deleted, 0 unchanged +Resources: 3 created, 0 changed, 0 deleted, 0 unchanged >>> [CLI] jobs get [JOB_ID] [ @@ -23,14 +22,6 @@ Resources: 4 created, 0 changed, 0 deleted, 0 unchanged { "default": "[VOLUME_ID]", "name": "volume_uuid" - }, - { - "default": "main.test-schema-[UNIQUE_NAME].mymodel", - "name": "model_full_name" - }, - { - "default": "main.test-schema-[UNIQUE_NAME].mymodel", - "name": "model_id" } ] @@ -38,22 +29,22 @@ Resources: 4 created, 0 changed, 0 deleted, 0 unchanged >>> update_file.py databricks.yml test-schema- test-schema-renamed- -=== The full_name and id of the volume and the model change with the schema, so the job is updated too +=== The volume's full_name and id change with the schema, so the job is updated too >>> [CLI] bundle plan update jobs.job1 update schemas.schema1 -Plan: 0 to add, 2 to change, 0 to delete, 2 unchanged +Plan: 0 to add, 2 to change, 0 to delete, 1 unchanged -=== Deploy passes the new full_name and id of the volume and the model to the job +=== Deploy passes the volume's new full_name and id to the job >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Updated jobs.job1 Updated schemas.schema1 Files: 2 uploaded, 0 deleted -Resources: 0 created, 2 changed, 0 deleted, 2 unchanged +Resources: 0 created, 2 changed, 0 deleted, 1 unchanged >>> print_requests.py //unity-catalog { @@ -79,26 +70,17 @@ Resources: 0 created, 2 changed, 0 deleted, 2 unchanged { "default": "[VOLUME_ID]", "name": "volume_uuid" - }, - { - "default": "main.test-schema-renamed-[UNIQUE_NAME].mymodel", - "name": "model_full_name" - }, - { - "default": "main.test-schema-renamed-[UNIQUE_NAME].mymodel", - "name": "model_id" } ] === Redeploy is a no-op >>> [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 4 unchanged +Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged >>> [CLI] bundle destroy --auto-approve The following resources will be deleted: delete resources.jobs.job1 - delete resources.registered_models.model1 delete resources.schemas.schema1 delete resources.volumes.volume1 @@ -113,4 +95,4 @@ is removed from the catalog, but the underlying files are not deleted: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default -Destroy: 4 deleted +Destroy: 3 deleted diff --git a/acceptance/bundle/resources/schemas/rename_with_volume_ref/script b/acceptance/bundle/resources/schemas/rename_with_volume_ref/script index dbaaf812709..6418f29011d 100644 --- a/acceptance/bundle/resources/schemas/rename_with_volume_ref/script +++ b/acceptance/bundle/resources/schemas/rename_with_volume_ref/script @@ -8,7 +8,7 @@ cleanup() { } trap cleanup EXIT -title "Deploy a schema, a volume and a registered model in it, and a job that reads their full_name and id" +title "Deploy a schema, a volume in it and a job that reads the volume's full_name and id" trace $CLI bundle deploy print_requests.py //unity-catalog &> LOG.deploy_requests JOB_ID=$($CLI bundle summary --output json | jq -r .resources.jobs.job1.id) @@ -19,10 +19,10 @@ trace $CLI jobs get "$JOB_ID" | jq .settings.parameters title "Rename the schema" trace update_file.py databricks.yml test-schema- test-schema-renamed- -title "The full_name and id of the volume and the model change with the schema, so the job is updated too" +title "The volume's full_name and id change with the schema, so the job is updated too" trace $CLI bundle plan -title "Deploy passes the new full_name and id of the volume and the model to the job" +title "Deploy passes the volume's new full_name and id to the job" trace $CLI bundle deploy trace print_requests.py //unity-catalog trace $CLI jobs get "$JOB_ID" | jq .settings.parameters From de19e2649b258ddd76eb5ac7e4b6b6c27db473d0 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 14:33:38 +0100 Subject: [PATCH 23/44] acc: keep grants/volume_change_name about the volume; the model case moves to its own test Co-authored-by: Isaac --- .../volume_change_name/databricks.yml.tmpl | 9 -- .../grants/volume_change_name/output.txt | 135 ++++-------------- .../grants/volume_change_name/script | 18 +-- 3 files changed, 30 insertions(+), 132 deletions(-) diff --git a/acceptance/bundle/resources/grants/volume_change_name/databricks.yml.tmpl b/acceptance/bundle/resources/grants/volume_change_name/databricks.yml.tmpl index dddb7d5229f..a8c9a407fda 100644 --- a/acceptance/bundle/resources/grants/volume_change_name/databricks.yml.tmpl +++ b/acceptance/bundle/resources/grants/volume_change_name/databricks.yml.tmpl @@ -15,12 +15,3 @@ resources: - principal: deco-test-user@databricks.com privileges: - READ_VOLUME - registered_models: - model1: - catalog_name: main - schema_name: ${resources.schemas.schema1.name} - name: mymodel - grants: - - principal: deco-test-user@databricks.com - privileges: - - APPLY_TAG diff --git a/acceptance/bundle/resources/grants/volume_change_name/output.txt b/acceptance/bundle/resources/grants/volume_change_name/output.txt index b7e8405ce04..8537be1c256 100644 --- a/acceptance/bundle/resources/grants/volume_change_name/output.txt +++ b/acceptance/bundle/resources/grants/volume_change_name/output.txt @@ -1,32 +1,31 @@ -=== Deploy a volume and a registered model with grants +=== Deploy a volume with grants >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... -Created registered_models.model1 -Created registered_models.model1.grants Created schemas.schema1 Created volumes.volume1 Created volumes.volume1.grants Files: 2 uploaded, 0 deleted -Resources: 5 created, 0 changed, 0 deleted, 0 unchanged +Resources: 3 created, 0 changed, 0 deleted, 0 unchanged ->>> print_requests.py --sort //unity-catalog +>>> print_requests.py //unity-catalog { - "method": "PATCH", - "path": "/api/2.1/unity-catalog/permissions/function/main.test-schema-[UNIQUE_NAME].mymodel", + "method": "POST", + "path": "/api/2.1/unity-catalog/schemas", "body": { - "changes": [ - { - "add": [ - "APPLY_TAG" - ], - "principal": "deco-test-user@databricks.com", - "remove": [ - "ALL_PRIVILEGES" - ] - } - ] + "catalog_name": "main", + "name": "test-schema-[UNIQUE_NAME]" + } +} +{ + "method": "POST", + "path": "/api/2.1/unity-catalog/volumes", + "body": { + "catalog_name": "main", + "name": "myvolume", + "schema_name": "test-schema-[UNIQUE_NAME]", + "volume_type": "MANAGED" } } { @@ -46,46 +45,14 @@ Resources: 5 created, 0 changed, 0 deleted, 0 unchanged ] } } -{ - "method": "POST", - "path": "/api/2.1/unity-catalog/models", - "body": { - "catalog_name": "main", - "name": "mymodel", - "schema_name": "test-schema-[UNIQUE_NAME]" - } -} -{ - "method": "POST", - "path": "/api/2.1/unity-catalog/schemas", - "body": { - "catalog_name": "main", - "name": "test-schema-[UNIQUE_NAME]" - } -} -{ - "method": "POST", - "path": "/api/2.1/unity-catalog/volumes", - "body": { - "catalog_name": "main", - "name": "myvolume", - "schema_name": "test-schema-[UNIQUE_NAME]", - "volume_type": "MANAGED" - } -} >>> read_state.py volumes volume1.grants id volumes volume1.grants id='volume/main.test-schema-[UNIQUE_NAME].myvolume' ->>> read_state.py registered_models model1.grants id -registered_models model1.grants id='function/main.test-schema-[UNIQUE_NAME].mymodel' - -=== Rename the volume and the model: their IDs change, and so do the IDs of their grants +=== Rename the volume: its ID changes, and so does the ID of its grants >>> update_file.py databricks.yml myvolume myvolume_renamed ->>> update_file.py databricks.yml mymodel mymodel_renamed - >>> [CLI] bundle plan --output json { "full_name": { @@ -97,54 +64,22 @@ registered_models model1.grants id='function/main.test-schema-[UNIQUE_NAME].mymo } } ->>> [CLI] bundle plan --output json -{ - "full_name": { - "action": "update_id", - "reason": "id_changes", - "old": "main.test-schema-[UNIQUE_NAME].mymodel", - "new": "", - "remote": "main.test-schema-[UNIQUE_NAME].mymodel" - } -} - -=== Deploy renames the volume and the model in place and applies the grants under the new names +=== Deploy renames the volume and applies the grants under the new name >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... -Updated registered_models.model1 -Updated registered_models.model1.grants Updated volumes.volume1 Updated volumes.volume1.grants Files: 1 uploaded, 0 deleted -Resources: 0 created, 4 changed, 0 deleted, 1 unchanged +Resources: 0 created, 2 changed, 0 deleted, 1 unchanged ->>> print_requests.py --sort //unity-catalog +>>> print_requests.py //unity-catalog { "method": "PATCH", - "path": "/api/2.1/unity-catalog/models/main.test-schema-[UNIQUE_NAME].mymodel", + "path": "/api/2.1/unity-catalog/volumes/main.test-schema-[UNIQUE_NAME].myvolume", "body": { - "catalog_name": "main", "comment": "", - "new_name": "mymodel_renamed", - "schema_name": "test-schema-[UNIQUE_NAME]" - } -} -{ - "method": "PATCH", - "path": "/api/2.1/unity-catalog/permissions/function/main.test-schema-[UNIQUE_NAME].mymodel_renamed", - "body": { - "changes": [ - { - "add": [ - "APPLY_TAG" - ], - "principal": "deco-test-user@databricks.com", - "remove": [ - "ALL_PRIVILEGES" - ] - } - ] + "new_name": "myvolume_renamed" } } { @@ -164,14 +99,6 @@ Resources: 0 created, 4 changed, 0 deleted, 1 unchanged ] } } -{ - "method": "PATCH", - "path": "/api/2.1/unity-catalog/volumes/main.test-schema-[UNIQUE_NAME].myvolume", - "body": { - "comment": "", - "new_name": "myvolume_renamed" - } -} >>> [CLI] grants get volume main.test-schema-[UNIQUE_NAME].myvolume_renamed { @@ -181,28 +108,16 @@ Resources: 0 created, 4 changed, 0 deleted, 1 unchanged ] } ->>> [CLI] grants get function main.test-schema-[UNIQUE_NAME].mymodel_renamed -{ - "principal": "deco-test-user@databricks.com", - "privileges": [ - "APPLY_TAG" - ] -} - === The grants are recorded under the new name, so the next plan is a no-op >>> read_state.py volumes volume1.grants id volumes volume1.grants id='volume/main.test-schema-[UNIQUE_NAME].myvolume_renamed' ->>> read_state.py registered_models model1.grants id -registered_models model1.grants id='function/main.test-schema-[UNIQUE_NAME].mymodel_renamed' - >>> [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 5 unchanged +Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged >>> [CLI] bundle destroy --auto-approve The following resources will be deleted: - delete resources.registered_models.model1 delete resources.schemas.schema1 delete resources.volumes.volume1 @@ -217,4 +132,4 @@ is removed from the catalog, but the underlying files are not deleted: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default -Destroy: 3 deleted +Destroy: 2 deleted diff --git a/acceptance/bundle/resources/grants/volume_change_name/script b/acceptance/bundle/resources/grants/volume_change_name/script index 21ce12a9c41..3ae81092846 100644 --- a/acceptance/bundle/resources/grants/volume_change_name/script +++ b/acceptance/bundle/resources/grants/volume_change_name/script @@ -1,7 +1,6 @@ envsubst < databricks.yml.tmpl > databricks.yml NEW_VOLUME="main.test-schema-${UNIQUE_NAME}.myvolume_renamed" -NEW_MODEL="main.test-schema-${UNIQUE_NAME}.mymodel_renamed" cleanup() { trace $CLI bundle destroy --auto-approve @@ -11,27 +10,20 @@ cleanup() { } trap cleanup EXIT -title "Deploy a volume and a registered model with grants" +title "Deploy a volume with grants" trace $CLI bundle deploy -# The volume and the model, and then their grants, are changed in parallel. -trace print_requests.py --sort //unity-catalog +trace print_requests.py //unity-catalog trace read_state.py volumes volume1.grants id -trace read_state.py registered_models model1.grants id -title "Rename the volume and the model: their IDs change, and so do the IDs of their grants" +title "Rename the volume: its ID changes, and so does the ID of its grants" trace update_file.py databricks.yml myvolume myvolume_renamed -trace update_file.py databricks.yml mymodel mymodel_renamed trace $CLI bundle plan --output json | jq '.plan["resources.volumes.volume1.grants"].changes' -trace $CLI bundle plan --output json | jq '.plan["resources.registered_models.model1.grants"].changes' -title "Deploy renames the volume and the model in place and applies the grants under the new names" +title "Deploy renames the volume and applies the grants under the new name" trace $CLI bundle deploy -# The volume and the model, and then their grants, are changed in parallel. -trace print_requests.py --sort //unity-catalog +trace print_requests.py //unity-catalog trace $CLI grants get volume "$NEW_VOLUME" | jq '.privilege_assignments[] | select(.principal == "deco-test-user@databricks.com")' -trace $CLI grants get function "$NEW_MODEL" | jq '.privilege_assignments[] | select(.principal == "deco-test-user@databricks.com")' title "The grants are recorded under the new name, so the next plan is a no-op" trace read_state.py volumes volume1.grants id -trace read_state.py registered_models model1.grants id trace $CLI bundle plan From 5cd6cdd97d05d2f346e5cb2d337769f711383549 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 14:36:37 +0100 Subject: [PATCH 24/44] acc: a registered model follows its catalog and schema renamed in one deploy Co-authored-by: Isaac --- .../databricks.yml.tmpl | 16 ++ .../rename_catalog_and_schema/out.test.toml | 3 + .../rename_catalog_and_schema/output.txt | 220 ++++++++++++++++++ .../rename_catalog_and_schema/script | 35 +++ .../rename_catalog_and_schema/test.toml | 14 ++ 5 files changed, 288 insertions(+) create mode 100644 acceptance/bundle/resources/registered_models/rename_catalog_and_schema/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/registered_models/rename_catalog_and_schema/out.test.toml create mode 100644 acceptance/bundle/resources/registered_models/rename_catalog_and_schema/output.txt create mode 100644 acceptance/bundle/resources/registered_models/rename_catalog_and_schema/script create mode 100644 acceptance/bundle/resources/registered_models/rename_catalog_and_schema/test.toml diff --git a/acceptance/bundle/resources/registered_models/rename_catalog_and_schema/databricks.yml.tmpl b/acceptance/bundle/resources/registered_models/rename_catalog_and_schema/databricks.yml.tmpl new file mode 100644 index 00000000000..957167b6ad5 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_catalog_and_schema/databricks.yml.tmpl @@ -0,0 +1,16 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +resources: + catalogs: + catalog1: + name: test_catalog_$UNIQUE_NAME + schemas: + schema1: + catalog_name: ${resources.catalogs.catalog1.name} + name: myschema + registered_models: + model1: + catalog_name: ${resources.catalogs.catalog1.name} + schema_name: ${resources.schemas.schema1.name} + name: mymodel diff --git a/acceptance/bundle/resources/registered_models/rename_catalog_and_schema/out.test.toml b/acceptance/bundle/resources/registered_models/rename_catalog_and_schema/out.test.toml new file mode 100644 index 00000000000..7a62f726f25 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_catalog_and_schema/out.test.toml @@ -0,0 +1,3 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] +EnvMatrix.READPLAN = ["", "1"] diff --git a/acceptance/bundle/resources/registered_models/rename_catalog_and_schema/output.txt b/acceptance/bundle/resources/registered_models/rename_catalog_and_schema/output.txt new file mode 100644 index 00000000000..895e3dce8a8 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_catalog_and_schema/output.txt @@ -0,0 +1,220 @@ + +=== Deploy a catalog with a schema and a registered model in it + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Created catalogs.catalog1 +Created registered_models.model1 +Created schemas.schema1 +Files: 2 uploaded, 0 deleted +Resources: 3 created, 0 changed, 0 deleted, 0 unchanged + +=== Rename the catalog and the schema in one deploy + +>>> update_file.py databricks.yml test_catalog_ test_catalog_renamed_ + +>>> update_file.py databricks.yml name: myschema name: myschema2 + +=== Both of the model's parents are renamed, so both its catalog_name and schema_name follow them + +>>> [CLI] bundle plan --output json +{ + "resources.catalogs.catalog1": { + "action": "update_id", + "new_state": { + "value": { + "name": "test_catalog_renamed_[UNIQUE_NAME]" + } + }, + "remote_state": { + "catalog_type": "MANAGED_CATALOG", + "created_by": "[USERNAME]", + "full_name": "test_catalog_[UNIQUE_NAME]", + "name": "test_catalog_[UNIQUE_NAME]", + "owner": "[USERNAME]" + }, + "changes": { + "name": { + "action": "update_id", + "reason": "id_changes", + "old": "test_catalog_[UNIQUE_NAME]", + "new": "test_catalog_renamed_[UNIQUE_NAME]", + "remote": "test_catalog_[UNIQUE_NAME]" + } + } + }, + "resources.registered_models.model1": { + "depends_on": [ + { + "node": "resources.catalogs.catalog1", + "label": "${resources.catalogs.catalog1.name}" + }, + { + "node": "resources.schemas.schema1", + "label": "${resources.schemas.schema1.name}" + } + ], + "action": "update_id", + "state_only": true, + "new_state": { + "value": { + "catalog_name": "test_catalog_renamed_[UNIQUE_NAME]", + "name": "mymodel", + "schema_name": "myschema2" + } + }, + "remote_state": { + "catalog_name": "test_catalog_[UNIQUE_NAME]", + "created_by": "[USERNAME]", + "full_name": "test_catalog_[UNIQUE_NAME].myschema.mymodel", + "name": "mymodel", + "owner": "[USERNAME]", + "schema_name": "myschema" + }, + "changes": { + "catalog_name": { + "action": "update_id", + "reason": "parent_renamed", + "old": "test_catalog_[UNIQUE_NAME]", + "new": "test_catalog_renamed_[UNIQUE_NAME]", + "remote": "test_catalog_[UNIQUE_NAME]" + }, + "created_by": { + "action": "skip", + "reason": "output_only", + "remote": "[USERNAME]" + }, + "full_name": { + "action": "skip", + "reason": "backend_default", + "remote": "test_catalog_[UNIQUE_NAME].myschema.mymodel" + }, + "owner": { + "action": "skip", + "reason": "backend_default", + "remote": "[USERNAME]" + }, + "schema_name": { + "action": "update_id", + "reason": "parent_renamed", + "old": "myschema", + "new": "myschema2", + "remote": "myschema" + } + } + }, + "resources.schemas.schema1": { + "depends_on": [ + { + "node": "resources.catalogs.catalog1", + "label": "${resources.catalogs.catalog1.name}" + } + ], + "action": "update_id", + "new_state": { + "value": { + "catalog_name": "test_catalog_renamed_[UNIQUE_NAME]", + "name": "myschema2" + } + }, + "remote_state": { + "catalog_name": "test_catalog_[UNIQUE_NAME]", + "catalog_type": "MANAGED_CATALOG", + "created_by": "[USERNAME]", + "full_name": "test_catalog_[UNIQUE_NAME].myschema", + "name": "myschema", + "owner": "[USERNAME]", + "schema_id": "[UUID]" + }, + "changes": { + "catalog_name": { + "action": "update_id", + "reason": "parent_renamed", + "old": "test_catalog_[UNIQUE_NAME]", + "new": "test_catalog_renamed_[UNIQUE_NAME]", + "remote": "test_catalog_[UNIQUE_NAME]" + }, + "name": { + "action": "update_id", + "reason": "id_changes", + "old": "myschema", + "new": "myschema2", + "remote": "myschema" + }, + "schema_id": { + "action": "skip", + "reason": "internal_id", + "old": "[UUID]", + "remote": "[UUID]" + } + } + } +} + +=== Deploy renames the catalog, then the schema under it. UC moves the model both times, so it gets no request + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Updated catalogs.catalog1 +Updated schemas.schema1 +Files: 2 uploaded, 0 deleted +Resources: 0 created, 2 changed, 0 deleted, 1 unchanged + +>>> print_requests.py //unity-catalog +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/catalogs/test_catalog_[UNIQUE_NAME]", + "body": { + "comment": "", + "custom_max_retention_hours": 0, + "new_name": "test_catalog_renamed_[UNIQUE_NAME]" + } +} +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/schemas/test_catalog_renamed_[UNIQUE_NAME].myschema", + "body": { + "comment": "", + "custom_max_retention_hours": 0, + "new_name": "myschema2" + } +} + +=== The model is under the new names and was not recreated + +>>> [CLI] registered-models get test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel +{ + "full_name": "test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel", + "created_at": [MODEL_CREATED_AT] +} + +>>> [CLI] bundle summary --output json +{ + "catalogs": { + "catalog1": "test_catalog_renamed_[UNIQUE_NAME]" + }, + "registered_models": { + "model1": "test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel" + }, + "schemas": { + "schema1": "test_catalog_renamed_[UNIQUE_NAME].myschema2" + } +} + +=== Redeploy is a no-op + +>>> [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.catalogs.catalog1 + delete resources.registered_models.model1 + 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: 3 deleted diff --git a/acceptance/bundle/resources/registered_models/rename_catalog_and_schema/script b/acceptance/bundle/resources/registered_models/rename_catalog_and_schema/script new file mode 100644 index 00000000000..676a9b261c8 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_catalog_and_schema/script @@ -0,0 +1,35 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +NEW_SCHEMA="test_catalog_renamed_${UNIQUE_NAME}.myschema2" + +cleanup() { + trace $CLI bundle destroy --auto-approve + + # Consume the destroy's requests so none are left recorded. + print_requests.py //unity-catalog &> LOG.destroy_requests +} +trap cleanup EXIT + +title "Deploy a catalog with a schema and a registered model in it" +trace $CLI bundle deploy +print_requests.py //unity-catalog &> LOG.deploy_requests +add_repl "$($CLI registered-models get "test_catalog_${UNIQUE_NAME}.myschema.mymodel" | jq -r .created_at)" MODEL_CREATED_AT + +title "Rename the catalog and the schema in one deploy" +trace update_file.py databricks.yml test_catalog_ test_catalog_renamed_ +trace update_file.py databricks.yml "name: myschema" "name: myschema2" + +title "Both of the model's parents are renamed, so both its catalog_name and schema_name follow them" +# Drop the remote_state fields that differ between clouds or from the test server. +trace $CLI bundle plan --output json | tee .databricks/plan.json | jq .plan | normalize_uc_payload.py created_at updated_at updated_by metastore_id browse_only effective_predictive_optimization_flag enable_predictive_optimization isolation_mode securable_type storage_location + +title "Deploy renames the catalog, then the schema under it. UC moves the model both times, so it gets no request" +trace $CLI bundle deploy $(readplanarg .databricks/plan.json) +trace print_requests.py //unity-catalog + +title "The model is under the new names and was not recreated" +trace $CLI registered-models get "$NEW_SCHEMA.mymodel" | jq '{full_name, created_at}' +trace $CLI bundle summary --output json | jq '.resources | map_values(map_values(.id))' + +title "Redeploy is a no-op" +trace $CLI bundle plan diff --git a/acceptance/bundle/resources/registered_models/rename_catalog_and_schema/test.toml b/acceptance/bundle/resources/registered_models/rename_catalog_and_schema/test.toml new file mode 100644 index 00000000000..ebd892fd9df --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_catalog_and_schema/test.toml @@ -0,0 +1,14 @@ +Cloud = true +EnvMatrix.READPLAN = ["", "1"] + +Ignore = [ + ".databricks", + ".gitignore", + "databricks.yml", +] + +# When READPLAN=1, "bundle deploy" is called as "bundle deploy --plan .databricks/plan.json". +# Normalize so both variants produce identical output. +[[Repls]] +Old = ' --plan .databricks/plan.json' +New = '' From 8ba9c363fd1e638d069aa238e960321211467a14 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 14:36:38 +0100 Subject: [PATCH 25/44] acc: a registered model moved out of a renamed schema is deleted where the rename moved it Co-authored-by: Isaac --- .../databricks.yml.tmpl | 16 ++ .../move_from_renamed_schema/out.test.toml | 3 + .../move_from_renamed_schema/output.txt | 190 ++++++++++++++++++ .../move_from_renamed_schema/script | 33 +++ .../move_from_renamed_schema/test.toml | 14 ++ 5 files changed, 256 insertions(+) create mode 100644 acceptance/bundle/resources/registered_models/move_from_renamed_schema/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/registered_models/move_from_renamed_schema/out.test.toml create mode 100644 acceptance/bundle/resources/registered_models/move_from_renamed_schema/output.txt create mode 100644 acceptance/bundle/resources/registered_models/move_from_renamed_schema/script create mode 100644 acceptance/bundle/resources/registered_models/move_from_renamed_schema/test.toml diff --git a/acceptance/bundle/resources/registered_models/move_from_renamed_schema/databricks.yml.tmpl b/acceptance/bundle/resources/registered_models/move_from_renamed_schema/databricks.yml.tmpl new file mode 100644 index 00000000000..d5d45b984fe --- /dev/null +++ b/acceptance/bundle/resources/registered_models/move_from_renamed_schema/databricks.yml.tmpl @@ -0,0 +1,16 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +resources: + schemas: + schema1: + catalog_name: main + name: test-schema1-$UNIQUE_NAME + schema2: + catalog_name: main + name: test-schema2-$UNIQUE_NAME + registered_models: + model1: + catalog_name: main + schema_name: ${resources.schemas.schema1.name} + name: mymodel diff --git a/acceptance/bundle/resources/registered_models/move_from_renamed_schema/out.test.toml b/acceptance/bundle/resources/registered_models/move_from_renamed_schema/out.test.toml new file mode 100644 index 00000000000..7a62f726f25 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/move_from_renamed_schema/out.test.toml @@ -0,0 +1,3 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] +EnvMatrix.READPLAN = ["", "1"] diff --git a/acceptance/bundle/resources/registered_models/move_from_renamed_schema/output.txt b/acceptance/bundle/resources/registered_models/move_from_renamed_schema/output.txt new file mode 100644 index 00000000000..b3fafcb0a62 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/move_from_renamed_schema/output.txt @@ -0,0 +1,190 @@ + +=== Deploy two schemas and a registered model in the first one + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Created registered_models.model1 +Created schemas.schema1 +Created schemas.schema2 +Files: 2 uploaded, 0 deleted +Resources: 3 created, 0 changed, 0 deleted, 0 unchanged + +=== Rename the first schema and move the model to the second one in one deploy. Moving the model recreates it + +>>> update_file.py databricks.yml test-schema1- test-schema1-renamed- + +>>> update_file.py databricks.yml schemas.schema1.name schemas.schema2.name + +>>> [CLI] bundle plan --output json +{ + "resources.registered_models.model1": { + "id": "main.test-schema1-renamed-[UNIQUE_NAME].mymodel", + "depends_on": [ + { + "node": "resources.schemas.schema2", + "label": "${resources.schemas.schema2.name}" + }, + { + "node": "resources.schemas.schema1", + "label": "${resources.schemas.schema1.name}" + } + ], + "action": "recreate", + "new_state": { + "value": { + "catalog_name": "main", + "name": "mymodel", + "schema_name": "test-schema2-[UNIQUE_NAME]" + } + }, + "remote_state": { + "catalog_name": "main", + "created_by": "[USERNAME]", + "full_name": "main.test-schema1-[UNIQUE_NAME].mymodel", + "name": "mymodel", + "owner": "[USERNAME]", + "schema_name": "test-schema1-[UNIQUE_NAME]" + }, + "changes": { + "created_by": { + "action": "skip", + "reason": "output_only", + "remote": "[USERNAME]" + }, + "full_name": { + "action": "skip", + "reason": "backend_default", + "remote": "main.test-schema1-[UNIQUE_NAME].mymodel" + }, + "owner": { + "action": "skip", + "reason": "backend_default", + "remote": "[USERNAME]" + }, + "schema_name": { + "action": "recreate", + "reason": "id_field", + "old": "test-schema1-[UNIQUE_NAME]", + "new": "test-schema2-[UNIQUE_NAME]", + "remote": "test-schema1-[UNIQUE_NAME]" + } + } + }, + "resources.schemas.schema1": { + "action": "update_id", + "new_state": { + "value": { + "catalog_name": "main", + "name": "test-schema1-renamed-[UNIQUE_NAME]" + } + }, + "remote_state": { + "catalog_name": "main", + "catalog_type": "MANAGED_CATALOG", + "created_by": "[USERNAME]", + "enable_predictive_optimization": "INHERIT", + "full_name": "main.test-schema1-[UNIQUE_NAME]", + "name": "test-schema1-[UNIQUE_NAME]", + "owner": "[USERNAME]", + "schema_id": "[UUID][0]" + }, + "changes": { + "name": { + "action": "update_id", + "reason": "id_changes", + "old": "test-schema1-[UNIQUE_NAME]", + "new": "test-schema1-renamed-[UNIQUE_NAME]", + "remote": "test-schema1-[UNIQUE_NAME]" + }, + "schema_id": { + "action": "skip", + "reason": "internal_id", + "old": "[UUID][0]", + "remote": "[UUID][0]" + } + } + }, + "resources.schemas.schema2": { + "action": "skip", + "remote_state": { + "catalog_name": "main", + "catalog_type": "MANAGED_CATALOG", + "created_by": "[USERNAME]", + "enable_predictive_optimization": "INHERIT", + "full_name": "main.test-schema2-[UNIQUE_NAME]", + "name": "test-schema2-[UNIQUE_NAME]", + "owner": "[USERNAME]", + "schema_id": "[UUID][1]" + }, + "changes": { + "schema_id": { + "action": "skip", + "reason": "internal_id", + "old": "[UUID][1]", + "remote": "[UUID][1]" + } + } + } +} + +>>> [CLI] bundle deploy --auto-approve +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Recreated registered_models.model1 +Updated schemas.schema1 +Files: 2 uploaded, 0 deleted +Resources: 1 created, 1 changed, 1 deleted, 1 unchanged + +>>> print_requests.py //unity-catalog +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/schemas/main.test-schema1-[UNIQUE_NAME]", + "body": { + "comment": "", + "custom_max_retention_hours": 0, + "new_name": "test-schema1-renamed-[UNIQUE_NAME]" + } +} +{ + "method": "DELETE", + "path": "/api/2.1/unity-catalog/models/main.test-schema1-renamed-[UNIQUE_NAME].mymodel" +} +{ + "method": "POST", + "path": "/api/2.1/unity-catalog/models", + "body": { + "catalog_name": "main", + "name": "mymodel", + "schema_name": "test-schema2-[UNIQUE_NAME]" + } +} + +=== The model is in the second schema + +>>> [CLI] registered-models get main.test-schema2-[UNIQUE_NAME].mymodel +{ + "full_name": "main.test-schema2-[UNIQUE_NAME].mymodel" +} + +=== The old model, moved with the renamed schema, was deleted there + +>>> musterr [CLI] registered-models get main.test-schema1-renamed-[UNIQUE_NAME].mymodel +Error: Routine or Model 'main.test-schema1-renamed-[UNIQUE_NAME].mymodel' does not exist. + +=== Redeploy is a no-op + +>>> [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.registered_models.model1 + delete resources.schemas.schema1 + delete resources.schemas.schema2 + +This action will result in the deletion of the following UC schemas. Any underlying data may be lost: + delete resources.schemas.schema1 + delete resources.schemas.schema2 + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default + +Destroy: 3 deleted diff --git a/acceptance/bundle/resources/registered_models/move_from_renamed_schema/script b/acceptance/bundle/resources/registered_models/move_from_renamed_schema/script new file mode 100644 index 00000000000..5c065d6da5d --- /dev/null +++ b/acceptance/bundle/resources/registered_models/move_from_renamed_schema/script @@ -0,0 +1,33 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +RENAMED_MODEL="main.test-schema1-renamed-${UNIQUE_NAME}.mymodel" +NEW_MODEL="main.test-schema2-${UNIQUE_NAME}.mymodel" + +cleanup() { + trace $CLI bundle destroy --auto-approve + + # Consume the destroy's requests so none are left recorded. + print_requests.py //unity-catalog &> LOG.destroy_requests +} +trap cleanup EXIT + +title "Deploy two schemas and a registered model in the first one" +trace $CLI bundle deploy +print_requests.py //unity-catalog &> LOG.deploy_requests + +title "Rename the first schema and move the model to the second one in one deploy. Moving the model recreates it" +trace update_file.py databricks.yml test-schema1- test-schema1-renamed- +trace update_file.py databricks.yml schemas.schema1.name schemas.schema2.name +# Drop the remote_state fields that differ between clouds or from the test server. +trace $CLI bundle plan --output json | tee .databricks/plan.json | jq .plan | normalize_uc_payload.py created_at updated_at updated_by metastore_id browse_only effective_predictive_optimization_flag storage_location +trace $CLI bundle deploy $(readplanarg .databricks/plan.json) --auto-approve +trace print_requests.py //unity-catalog + +title "The model is in the second schema" +trace $CLI registered-models get "$NEW_MODEL" | jq '{full_name}' + +title "The old model, moved with the renamed schema, was deleted there" +trace musterr $CLI registered-models get "$RENAMED_MODEL" + +title "Redeploy is a no-op" +trace $CLI bundle plan diff --git a/acceptance/bundle/resources/registered_models/move_from_renamed_schema/test.toml b/acceptance/bundle/resources/registered_models/move_from_renamed_schema/test.toml new file mode 100644 index 00000000000..ebd892fd9df --- /dev/null +++ b/acceptance/bundle/resources/registered_models/move_from_renamed_schema/test.toml @@ -0,0 +1,14 @@ +Cloud = true +EnvMatrix.READPLAN = ["", "1"] + +Ignore = [ + ".databricks", + ".gitignore", + "databricks.yml", +] + +# When READPLAN=1, "bundle deploy" is called as "bundle deploy --plan .databricks/plan.json". +# Normalize so both variants produce identical output. +[[Repls]] +Old = ' --plan .databricks/plan.json' +New = '' From e73ee3452873247aad999971a7e7a5f02ea13ea7 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 14:36:39 +0100 Subject: [PATCH 26/44] acc: grants follow a registered model's in-place rename Co-authored-by: Isaac --- .../databricks.yml.tmpl | 17 +++ .../out.test.toml | 2 + .../registered_model_change_name/output.txt | 130 ++++++++++++++++++ .../registered_model_change_name/script | 29 ++++ 4 files changed, 178 insertions(+) create mode 100644 acceptance/bundle/resources/grants/registered_model_change_name/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/grants/registered_model_change_name/out.test.toml create mode 100644 acceptance/bundle/resources/grants/registered_model_change_name/output.txt create mode 100644 acceptance/bundle/resources/grants/registered_model_change_name/script diff --git a/acceptance/bundle/resources/grants/registered_model_change_name/databricks.yml.tmpl b/acceptance/bundle/resources/grants/registered_model_change_name/databricks.yml.tmpl new file mode 100644 index 00000000000..f3fbb05ae6d --- /dev/null +++ b/acceptance/bundle/resources/grants/registered_model_change_name/databricks.yml.tmpl @@ -0,0 +1,17 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +resources: + schemas: + schema1: + catalog_name: main + name: test-schema-$UNIQUE_NAME + registered_models: + model1: + catalog_name: main + schema_name: ${resources.schemas.schema1.name} + name: mymodel + grants: + - principal: deco-test-user@databricks.com + privileges: + - APPLY_TAG diff --git a/acceptance/bundle/resources/grants/registered_model_change_name/out.test.toml b/acceptance/bundle/resources/grants/registered_model_change_name/out.test.toml new file mode 100644 index 00000000000..0f167effef1 --- /dev/null +++ b/acceptance/bundle/resources/grants/registered_model_change_name/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/grants/registered_model_change_name/output.txt b/acceptance/bundle/resources/grants/registered_model_change_name/output.txt new file mode 100644 index 00000000000..a53f0e03a28 --- /dev/null +++ b/acceptance/bundle/resources/grants/registered_model_change_name/output.txt @@ -0,0 +1,130 @@ + +=== Deploy a registered model with grants + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Created registered_models.model1 +Created registered_models.model1.grants +Created schemas.schema1 +Files: 2 uploaded, 0 deleted +Resources: 3 created, 0 changed, 0 deleted, 0 unchanged + +>>> print_requests.py //unity-catalog +{ + "method": "POST", + "path": "/api/2.1/unity-catalog/schemas", + "body": { + "catalog_name": "main", + "name": "test-schema-[UNIQUE_NAME]" + } +} +{ + "method": "POST", + "path": "/api/2.1/unity-catalog/models", + "body": { + "catalog_name": "main", + "name": "mymodel", + "schema_name": "test-schema-[UNIQUE_NAME]" + } +} +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/permissions/function/main.test-schema-[UNIQUE_NAME].mymodel", + "body": { + "changes": [ + { + "add": [ + "APPLY_TAG" + ], + "principal": "deco-test-user@databricks.com", + "remove": [ + "ALL_PRIVILEGES" + ] + } + ] + } +} + +>>> read_state.py registered_models model1.grants id +registered_models model1.grants id='function/main.test-schema-[UNIQUE_NAME].mymodel' + +=== Rename the model: its ID changes, and so does the ID of its grants + +>>> update_file.py databricks.yml mymodel mymodel_renamed + +>>> [CLI] bundle plan --output json +{ + "full_name": { + "action": "update_id", + "reason": "id_changes", + "old": "main.test-schema-[UNIQUE_NAME].mymodel", + "new": "", + "remote": "main.test-schema-[UNIQUE_NAME].mymodel" + } +} + +=== Deploy renames the model in place and applies the grants under the new name + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Updated registered_models.model1 +Updated registered_models.model1.grants +Files: 1 uploaded, 0 deleted +Resources: 0 created, 2 changed, 0 deleted, 1 unchanged + +>>> print_requests.py //unity-catalog +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/models/main.test-schema-[UNIQUE_NAME].mymodel", + "body": { + "catalog_name": "main", + "comment": "", + "new_name": "mymodel_renamed", + "schema_name": "test-schema-[UNIQUE_NAME]" + } +} +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/permissions/function/main.test-schema-[UNIQUE_NAME].mymodel_renamed", + "body": { + "changes": [ + { + "add": [ + "APPLY_TAG" + ], + "principal": "deco-test-user@databricks.com", + "remove": [ + "ALL_PRIVILEGES" + ] + } + ] + } +} + +>>> [CLI] grants get function main.test-schema-[UNIQUE_NAME].mymodel_renamed +{ + "principal": "deco-test-user@databricks.com", + "privileges": [ + "APPLY_TAG" + ] +} + +=== The grants are recorded under the new name, so the next plan is a no-op + +>>> read_state.py registered_models model1.grants id +registered_models model1.grants id='function/main.test-schema-[UNIQUE_NAME].mymodel_renamed' + +>>> [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.registered_models.model1 + 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: 2 deleted diff --git a/acceptance/bundle/resources/grants/registered_model_change_name/script b/acceptance/bundle/resources/grants/registered_model_change_name/script new file mode 100644 index 00000000000..c2668c183e5 --- /dev/null +++ b/acceptance/bundle/resources/grants/registered_model_change_name/script @@ -0,0 +1,29 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +NEW_MODEL="main.test-schema-${UNIQUE_NAME}.mymodel_renamed" + +cleanup() { + trace $CLI bundle destroy --auto-approve + + # Consume the destroy's requests so none are left recorded. + print_requests.py //unity-catalog &> LOG.destroy_requests +} +trap cleanup EXIT + +title "Deploy a registered model with grants" +trace $CLI bundle deploy +trace print_requests.py //unity-catalog +trace read_state.py registered_models model1.grants id + +title "Rename the model: its ID changes, and so does the ID of its grants" +trace update_file.py databricks.yml mymodel mymodel_renamed +trace $CLI bundle plan --output json | jq '.plan["resources.registered_models.model1.grants"].changes' + +title "Deploy renames the model in place and applies the grants under the new name" +trace $CLI bundle deploy +trace print_requests.py //unity-catalog +trace $CLI grants get function "$NEW_MODEL" | jq '.privilege_assignments[] | select(.principal == "deco-test-user@databricks.com")' + +title "The grants are recorded under the new name, so the next plan is a no-op" +trace read_state.py registered_models model1.grants id +trace $CLI bundle plan From 52b51f2516214f808ef67e7cdc9e064bcbe3c444 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 14:38:02 +0100 Subject: [PATCH 27/44] acc: trim registered_models/rename to the model's own rename The schema and catalog rename steps are covered by schemas/rename_then_change, schemas/rename_with_model_and_secret, catalogs/rename and registered_models/rename_catalog_and_schema. Co-authored-by: Isaac --- .../rename/databricks.yml.tmpl | 9 +- .../registered_models/rename/output.txt | 394 ++---------------- .../resources/registered_models/rename/script | 34 +- 3 files changed, 45 insertions(+), 392 deletions(-) diff --git a/acceptance/bundle/resources/registered_models/rename/databricks.yml.tmpl b/acceptance/bundle/resources/registered_models/rename/databricks.yml.tmpl index 4b30bc96c3d..6f739c9c6c5 100644 --- a/acceptance/bundle/resources/registered_models/rename/databricks.yml.tmpl +++ b/acceptance/bundle/resources/registered_models/rename/databricks.yml.tmpl @@ -2,16 +2,13 @@ bundle: name: test-bundle-$UNIQUE_NAME resources: - catalogs: - catalog1: - name: test_catalog_$UNIQUE_NAME schemas: schema1: - catalog_name: ${resources.catalogs.catalog1.name} - name: myschema + catalog_name: main + name: test-schema-$UNIQUE_NAME registered_models: model1: - catalog_name: ${resources.catalogs.catalog1.name} + catalog_name: main schema_name: ${resources.schemas.schema1.name} name: mymodel comment: c1 diff --git a/acceptance/bundle/resources/registered_models/rename/output.txt b/acceptance/bundle/resources/registered_models/rename/output.txt index 9546c71c49a..dc9bf99b35b 100644 --- a/acceptance/bundle/resources/registered_models/rename/output.txt +++ b/acceptance/bundle/resources/registered_models/rename/output.txt @@ -1,38 +1,30 @@ -=== Deploy a catalog with a schema and a registered model in it +=== Deploy a schema with a registered model in it >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... -Created catalogs.catalog1 Created registered_models.model1 Created schemas.schema1 Files: 2 uploaded, 0 deleted -Resources: 3 created, 0 changed, 0 deleted, 0 unchanged +Resources: 2 created, 0 changed, 0 deleted, 0 unchanged >>> print_requests.py //unity-catalog -{ - "method": "POST", - "path": "/api/2.1/unity-catalog/catalogs", - "body": { - "name": "test_catalog_[UNIQUE_NAME]" - } -} { "method": "POST", "path": "/api/2.1/unity-catalog/schemas", "body": { - "catalog_name": "test_catalog_[UNIQUE_NAME]", - "name": "myschema" + "catalog_name": "main", + "name": "test-schema-[UNIQUE_NAME]" } } { "method": "POST", "path": "/api/2.1/unity-catalog/models", "body": { - "catalog_name": "test_catalog_[UNIQUE_NAME]", + "catalog_name": "main", "comment": "c1", "name": "mymodel", - "schema_name": "myschema" + "schema_name": "test-schema-[UNIQUE_NAME]" } } @@ -42,22 +34,8 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged >>> [CLI] bundle plan --output json { - "resources.catalogs.catalog1": { - "action": "skip", - "remote_state": { - "catalog_type": "MANAGED_CATALOG", - "created_by": "[USERNAME]", - "full_name": "test_catalog_[UNIQUE_NAME]", - "name": "test_catalog_[UNIQUE_NAME]", - "owner": "[USERNAME]" - } - }, "resources.registered_models.model1": { "depends_on": [ - { - "node": "resources.catalogs.catalog1", - "label": "${resources.catalogs.catalog1.name}" - }, { "node": "resources.schemas.schema1", "label": "${resources.schemas.schema1.name}" @@ -66,20 +44,20 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged "action": "update_id", "new_state": { "value": { - "catalog_name": "test_catalog_[UNIQUE_NAME]", + "catalog_name": "main", "comment": "c1", "name": "mymodel2", - "schema_name": "myschema" + "schema_name": "test-schema-[UNIQUE_NAME]" } }, "remote_state": { - "catalog_name": "test_catalog_[UNIQUE_NAME]", + "catalog_name": "main", "comment": "c1", "created_by": "[USERNAME]", - "full_name": "test_catalog_[UNIQUE_NAME].myschema.mymodel", + "full_name": "main.test-schema-[UNIQUE_NAME].mymodel", "name": "mymodel", "owner": "[USERNAME]", - "schema_name": "myschema" + "schema_name": "test-schema-[UNIQUE_NAME]" }, "changes": { "created_by": { @@ -90,7 +68,7 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged "full_name": { "action": "skip", "reason": "backend_default", - "remote": "test_catalog_[UNIQUE_NAME].myschema.mymodel" + "remote": "main.test-schema-[UNIQUE_NAME].mymodel" }, "name": { "action": "update_id", @@ -107,19 +85,14 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged } }, "resources.schemas.schema1": { - "depends_on": [ - { - "node": "resources.catalogs.catalog1", - "label": "${resources.catalogs.catalog1.name}" - } - ], "action": "skip", "remote_state": { - "catalog_name": "test_catalog_[UNIQUE_NAME]", + "catalog_name": "main", "catalog_type": "MANAGED_CATALOG", "created_by": "[USERNAME]", - "full_name": "test_catalog_[UNIQUE_NAME].myschema", - "name": "myschema", + "enable_predictive_optimization": "INHERIT", + "full_name": "main.test-schema-[UNIQUE_NAME]", + "name": "test-schema-[UNIQUE_NAME]", "owner": "[USERNAME]", "schema_id": "[UUID]" }, @@ -138,320 +111,23 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Updated registered_models.model1 Files: 1 uploaded, 0 deleted -Resources: 0 created, 1 changed, 0 deleted, 2 unchanged +Resources: 0 created, 1 changed, 0 deleted, 1 unchanged >>> print_requests.py //unity-catalog { "method": "PATCH", - "path": "/api/2.1/unity-catalog/models/test_catalog_[UNIQUE_NAME].myschema.mymodel", + "path": "/api/2.1/unity-catalog/models/main.test-schema-[UNIQUE_NAME].mymodel", "body": { - "catalog_name": "test_catalog_[UNIQUE_NAME]", + "catalog_name": "main", "comment": "c1", "new_name": "mymodel2", - "schema_name": "myschema" - } -} - ->>> [CLI] registered-models get test_catalog_[UNIQUE_NAME].myschema.mymodel2 -{ - "full_name": "test_catalog_[UNIQUE_NAME].myschema.mymodel2", - "created_at": [MODEL_CREATED_AT] -} - -=== Rename the schema: UC moves the model with it, so the model is re-keyed without a request - ->>> update_file.py databricks.yml name: myschema name: myschema2 - ->>> [CLI] bundle plan --output json -{ - "resources.catalogs.catalog1": { - "action": "skip", - "remote_state": { - "catalog_type": "MANAGED_CATALOG", - "created_by": "[USERNAME]", - "full_name": "test_catalog_[UNIQUE_NAME]", - "name": "test_catalog_[UNIQUE_NAME]", - "owner": "[USERNAME]" - } - }, - "resources.registered_models.model1": { - "depends_on": [ - { - "node": "resources.catalogs.catalog1", - "label": "${resources.catalogs.catalog1.name}" - }, - { - "node": "resources.schemas.schema1", - "label": "${resources.schemas.schema1.name}" - } - ], - "action": "update_id", - "state_only": true, - "new_state": { - "value": { - "catalog_name": "test_catalog_[UNIQUE_NAME]", - "comment": "c1", - "name": "mymodel2", - "schema_name": "myschema2" - } - }, - "remote_state": { - "catalog_name": "test_catalog_[UNIQUE_NAME]", - "comment": "c1", - "created_by": "[USERNAME]", - "full_name": "test_catalog_[UNIQUE_NAME].myschema.mymodel2", - "name": "mymodel2", - "owner": "[USERNAME]", - "schema_name": "myschema" - }, - "changes": { - "created_by": { - "action": "skip", - "reason": "output_only", - "remote": "[USERNAME]" - }, - "full_name": { - "action": "skip", - "reason": "backend_default", - "remote": "test_catalog_[UNIQUE_NAME].myschema.mymodel2" - }, - "owner": { - "action": "skip", - "reason": "backend_default", - "remote": "[USERNAME]" - }, - "schema_name": { - "action": "update_id", - "reason": "parent_renamed", - "old": "myschema", - "new": "myschema2", - "remote": "myschema" - } - } - }, - "resources.schemas.schema1": { - "depends_on": [ - { - "node": "resources.catalogs.catalog1", - "label": "${resources.catalogs.catalog1.name}" - } - ], - "action": "update_id", - "new_state": { - "value": { - "catalog_name": "test_catalog_[UNIQUE_NAME]", - "name": "myschema2" - } - }, - "remote_state": { - "catalog_name": "test_catalog_[UNIQUE_NAME]", - "catalog_type": "MANAGED_CATALOG", - "created_by": "[USERNAME]", - "full_name": "test_catalog_[UNIQUE_NAME].myschema", - "name": "myschema", - "owner": "[USERNAME]", - "schema_id": "[UUID]" - }, - "changes": { - "name": { - "action": "update_id", - "reason": "id_changes", - "old": "myschema", - "new": "myschema2", - "remote": "myschema" - }, - "schema_id": { - "action": "skip", - "reason": "internal_id", - "old": "[UUID]", - "remote": "[UUID]" - } - } - } -} - ->>> [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... -Updated schemas.schema1 -Files: 1 uploaded, 0 deleted -Resources: 0 created, 1 changed, 0 deleted, 2 unchanged - ->>> print_requests.py //unity-catalog -{ - "method": "PATCH", - "path": "/api/2.1/unity-catalog/schemas/test_catalog_[UNIQUE_NAME].myschema", - "body": { - "comment": "", - "custom_max_retention_hours": 0, - "new_name": "myschema2" + "schema_name": "test-schema-[UNIQUE_NAME]" } } ->>> [CLI] registered-models get test_catalog_[UNIQUE_NAME].myschema2.mymodel2 +>>> [CLI] registered-models get main.test-schema-[UNIQUE_NAME].mymodel2 { - "full_name": "test_catalog_[UNIQUE_NAME].myschema2.mymodel2", - "created_at": [MODEL_CREATED_AT] -} - -=== Rename the catalog: the model is re-keyed again - ->>> update_file.py databricks.yml test_catalog_ test_catalog_renamed_ - ->>> [CLI] bundle plan --output json -{ - "resources.catalogs.catalog1": { - "action": "update_id", - "new_state": { - "value": { - "name": "test_catalog_renamed_[UNIQUE_NAME]" - } - }, - "remote_state": { - "catalog_type": "MANAGED_CATALOG", - "created_by": "[USERNAME]", - "full_name": "test_catalog_[UNIQUE_NAME]", - "name": "test_catalog_[UNIQUE_NAME]", - "owner": "[USERNAME]" - }, - "changes": { - "name": { - "action": "update_id", - "reason": "id_changes", - "old": "test_catalog_[UNIQUE_NAME]", - "new": "test_catalog_renamed_[UNIQUE_NAME]", - "remote": "test_catalog_[UNIQUE_NAME]" - } - } - }, - "resources.registered_models.model1": { - "depends_on": [ - { - "node": "resources.catalogs.catalog1", - "label": "${resources.catalogs.catalog1.name}" - }, - { - "node": "resources.schemas.schema1", - "label": "${resources.schemas.schema1.name}" - } - ], - "action": "update_id", - "state_only": true, - "new_state": { - "value": { - "catalog_name": "test_catalog_renamed_[UNIQUE_NAME]", - "comment": "c1", - "name": "mymodel2", - "schema_name": "myschema2" - } - }, - "remote_state": { - "catalog_name": "test_catalog_[UNIQUE_NAME]", - "comment": "c1", - "created_by": "[USERNAME]", - "full_name": "test_catalog_[UNIQUE_NAME].myschema2.mymodel2", - "name": "mymodel2", - "owner": "[USERNAME]", - "schema_name": "myschema2" - }, - "changes": { - "catalog_name": { - "action": "update_id", - "reason": "parent_renamed", - "old": "test_catalog_[UNIQUE_NAME]", - "new": "test_catalog_renamed_[UNIQUE_NAME]", - "remote": "test_catalog_[UNIQUE_NAME]" - }, - "created_by": { - "action": "skip", - "reason": "output_only", - "remote": "[USERNAME]" - }, - "full_name": { - "action": "skip", - "reason": "backend_default", - "remote": "test_catalog_[UNIQUE_NAME].myschema2.mymodel2" - }, - "owner": { - "action": "skip", - "reason": "backend_default", - "remote": "[USERNAME]" - } - } - }, - "resources.schemas.schema1": { - "depends_on": [ - { - "node": "resources.catalogs.catalog1", - "label": "${resources.catalogs.catalog1.name}" - } - ], - "action": "update_id", - "state_only": true, - "new_state": { - "value": { - "catalog_name": "test_catalog_renamed_[UNIQUE_NAME]", - "name": "myschema2" - } - }, - "remote_state": { - "catalog_name": "test_catalog_[UNIQUE_NAME]", - "catalog_type": "MANAGED_CATALOG", - "comment": "", - "created_by": "[USERNAME]", - "custom_max_retention_hours": 0, - "full_name": "test_catalog_[UNIQUE_NAME].myschema2", - "name": "myschema2", - "owner": "[USERNAME]", - "schema_id": "[UUID]" - }, - "changes": { - "catalog_name": { - "action": "update_id", - "reason": "parent_renamed", - "old": "test_catalog_[UNIQUE_NAME]", - "new": "test_catalog_renamed_[UNIQUE_NAME]", - "remote": "test_catalog_[UNIQUE_NAME]" - }, - "comment": { - "action": "skip", - "reason": "empty", - "remote": "" - }, - "custom_max_retention_hours": { - "action": "skip", - "reason": "empty", - "remote": 0 - }, - "schema_id": { - "action": "skip", - "reason": "internal_id", - "old": "[UUID]", - "remote": "[UUID]" - } - } - } -} - ->>> [CLI] bundle deploy -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... -Updated catalogs.catalog1 -Files: 1 uploaded, 0 deleted -Resources: 0 created, 1 changed, 0 deleted, 2 unchanged - ->>> print_requests.py //unity-catalog -{ - "method": "PATCH", - "path": "/api/2.1/unity-catalog/catalogs/test_catalog_[UNIQUE_NAME]", - "body": { - "comment": "", - "custom_max_retention_hours": 0, - "new_name": "test_catalog_renamed_[UNIQUE_NAME]" - } -} - ->>> [CLI] registered-models get test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel2 -{ - "full_name": "test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel2", + "full_name": "main.test-schema-[UNIQUE_NAME].mymodel2", "created_at": [MODEL_CREATED_AT] } @@ -465,48 +141,44 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Updated registered_models.model1 Files: 1 uploaded, 0 deleted -Resources: 0 created, 1 changed, 0 deleted, 2 unchanged +Resources: 0 created, 1 changed, 0 deleted, 1 unchanged >>> print_requests.py //unity-catalog { "method": "PATCH", - "path": "/api/2.1/unity-catalog/models/test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel2", + "path": "/api/2.1/unity-catalog/models/main.test-schema-[UNIQUE_NAME].mymodel2", "body": { - "catalog_name": "test_catalog_renamed_[UNIQUE_NAME]", + "catalog_name": "main", "comment": "c2", "new_name": "mymodel3", - "schema_name": "myschema2" + "schema_name": "test-schema-[UNIQUE_NAME]" } } ->>> [CLI] registered-models get test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel3 +>>> [CLI] registered-models get main.test-schema-[UNIQUE_NAME].mymodel3 { - "full_name": "test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel3", + "full_name": "main.test-schema-[UNIQUE_NAME].mymodel3", "comment": "c2", "created_at": [MODEL_CREATED_AT] } -=== The state tracks the new paths and the plan is a no-op +=== The state tracks the new name and the plan is a no-op >>> [CLI] bundle summary --output json { - "catalogs": { - "catalog1": "test_catalog_renamed_[UNIQUE_NAME]" - }, "registered_models": { - "model1": "test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel3" + "model1": "main.test-schema-[UNIQUE_NAME].mymodel3" }, "schemas": { - "schema1": "test_catalog_renamed_[UNIQUE_NAME].myschema2" + "schema1": "main.test-schema-[UNIQUE_NAME]" } } >>> [CLI] bundle plan -Plan: 0 to add, 0 to change, 0 to delete, 3 unchanged +Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged >>> [CLI] bundle destroy --auto-approve The following resources will be deleted: - delete resources.catalogs.catalog1 delete resources.registered_models.model1 delete resources.schemas.schema1 @@ -515,4 +187,4 @@ This action will result in the deletion of the following UC schemas. Any underly All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default -Destroy: 3 deleted +Destroy: 2 deleted diff --git a/acceptance/bundle/resources/registered_models/rename/script b/acceptance/bundle/resources/registered_models/rename/script index d2e8cf80c4e..b173bf86fe8 100644 --- a/acceptance/bundle/resources/registered_models/rename/script +++ b/acceptance/bundle/resources/registered_models/rename/script @@ -1,5 +1,7 @@ envsubst < databricks.yml.tmpl > databricks.yml +SCHEMA="main.test-schema-${UNIQUE_NAME}" + cleanup() { trace $CLI bundle destroy --auto-approve @@ -8,44 +10,26 @@ 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 | tee .databricks/plan.json | jq .plan | normalize_uc_payload.py created_at updated_at updated_by metastore_id browse_only effective_predictive_optimization_flag enable_predictive_optimization isolation_mode securable_type storage_location -} - -title "Deploy a catalog with a schema and a registered model in it" +title "Deploy a schema with a registered model in it" trace $CLI bundle deploy trace print_requests.py //unity-catalog -add_repl "$($CLI registered-models get "test_catalog_${UNIQUE_NAME}.myschema.mymodel" | jq -r .created_at)" MODEL_CREATED_AT +add_repl "$($CLI registered-models get "$SCHEMA.mymodel" | jq -r .created_at)" MODEL_CREATED_AT title "Rename the model: it is renamed in place, keeping its versions" trace update_file.py databricks.yml "name: mymodel" "name: mymodel2" -plan -trace $CLI bundle deploy $(readplanarg .databricks/plan.json) -trace print_requests.py //unity-catalog -trace $CLI registered-models get "test_catalog_${UNIQUE_NAME}.myschema.mymodel2" | jq '{full_name, created_at}' - -title "Rename the schema: UC moves the model with it, so the model is re-keyed without a request" -trace update_file.py databricks.yml "name: myschema" "name: myschema2" -plan -trace $CLI bundle deploy $(readplanarg .databricks/plan.json) -trace print_requests.py //unity-catalog -trace $CLI registered-models get "test_catalog_${UNIQUE_NAME}.myschema2.mymodel2" | jq '{full_name, created_at}' - -title "Rename the catalog: the model is re-keyed again" -trace update_file.py databricks.yml test_catalog_ test_catalog_renamed_ -plan +# Drop the remote_state fields that differ between clouds or from the test server. +trace $CLI bundle plan --output json | tee .databricks/plan.json | jq .plan | normalize_uc_payload.py created_at updated_at updated_by metastore_id browse_only effective_predictive_optimization_flag storage_location trace $CLI bundle deploy $(readplanarg .databricks/plan.json) trace print_requests.py //unity-catalog -trace $CLI registered-models get "test_catalog_renamed_${UNIQUE_NAME}.myschema2.mymodel2" | jq '{full_name, created_at}' +trace $CLI registered-models get "$SCHEMA.mymodel2" | jq '{full_name, created_at}' title "Rename the model and change its comment in one deploy: both go in one PATCH" trace update_file.py databricks.yml "name: mymodel2" "name: mymodel3" trace update_file.py databricks.yml "comment: c1" "comment: c2" trace $CLI bundle deploy trace print_requests.py //unity-catalog -trace $CLI registered-models get "test_catalog_renamed_${UNIQUE_NAME}.myschema2.mymodel3" | jq '{full_name, comment, created_at}' +trace $CLI registered-models get "$SCHEMA.mymodel3" | jq '{full_name, comment, created_at}' -title "The state tracks the new paths and the plan is a no-op" +title "The state tracks the new name and the plan is a no-op" trace $CLI bundle summary --output json | jq '.resources | map_values(map_values(.id))' trace $CLI bundle plan From 37b09019ea8d0a57e00cbd441a1cca93b2962099 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 14:42:36 +0100 Subject: [PATCH 28/44] testserver: reject creating a registered model that already exists, as UC does Verified on AWS: 400 RESOURCE_ALREADY_EXISTS "Routine or Model '' already exists". Co-authored-by: Isaac --- libs/testserver/registered_models.go | 11 ++++++++++ libs/testserver/registered_models_test.go | 25 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 libs/testserver/registered_models_test.go diff --git a/libs/testserver/registered_models.go b/libs/testserver/registered_models.go index 9f91b98b874..908ed0b09c7 100644 --- a/libs/testserver/registered_models.go +++ b/libs/testserver/registered_models.go @@ -28,6 +28,17 @@ func (s *FakeWorkspace) RegisteredModelsCreate(req Request) Response { // Build full name from catalog.schema.name fullName := createRequest.CatalogName + "." + createRequest.SchemaName + "." + createRequest.Name + // UC names the model by its short name here (verified on AWS). + if _, ok := s.RegisteredModels[fullName]; ok { + return Response{ + StatusCode: http.StatusBadRequest, + Body: map[string]string{ + "error_code": "RESOURCE_ALREADY_EXISTS", + "message": fmt.Sprintf("Routine or Model '%s' already exists", createRequest.Name), + }, + } + } + registeredModel := catalog.RegisteredModelInfo{ CatalogName: createRequest.CatalogName, Comment: createRequest.Comment, diff --git a/libs/testserver/registered_models_test.go b/libs/testserver/registered_models_test.go new file mode 100644 index 00000000000..81f955ebc1f --- /dev/null +++ b/libs/testserver/registered_models_test.go @@ -0,0 +1,25 @@ +package testserver + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestRegisteredModelsCreate_RejectsExistingModel(t *testing.T) { + workspace := NewFakeWorkspace("http://test", "dbapi123") + request := Request{Body: []byte(`{"catalog_name": "main", "schema_name": "default", "name": "mymodel", "comment": "first"}`)} + + require.Equal(t, 0, workspace.RegisteredModelsCreate(request).StatusCode) + + response := workspace.RegisteredModelsCreate(Request{Body: []byte(`{"catalog_name": "main", "schema_name": "default", "name": "mymodel", "comment": "second"}`)}) + assert.Equal(t, 400, response.StatusCode) + assert.Equal(t, map[string]string{ + "error_code": "RESOURCE_ALREADY_EXISTS", + "message": "Routine or Model 'mymodel' already exists", + }, response.Body) + + // The existing model is kept as it was. + assert.Equal(t, "first", workspace.RegisteredModels["main.default.mymodel"].Comment) +} From 8951c779eba6077a5ae40323d2a23a3cfe976104 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 14:46:32 +0100 Subject: [PATCH 29/44] acc: a model whose schema is renamed out of band is created again (Badness) Co-authored-by: Isaac --- .../databricks.yml.tmpl | 13 ++++ .../parent_rename_out_of_band/out.test.toml | 2 + .../parent_rename_out_of_band/output.txt | 67 +++++++++++++++++++ .../parent_rename_out_of_band/script | 29 ++++++++ .../parent_rename_out_of_band/test.toml | 8 +++ 5 files changed, 119 insertions(+) create mode 100644 acceptance/bundle/resources/registered_models/parent_rename_out_of_band/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/registered_models/parent_rename_out_of_band/out.test.toml create mode 100644 acceptance/bundle/resources/registered_models/parent_rename_out_of_band/output.txt create mode 100644 acceptance/bundle/resources/registered_models/parent_rename_out_of_band/script create mode 100644 acceptance/bundle/resources/registered_models/parent_rename_out_of_band/test.toml diff --git a/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/databricks.yml.tmpl b/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/databricks.yml.tmpl new file mode 100644 index 00000000000..630cfc75a4a --- /dev/null +++ b/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/databricks.yml.tmpl @@ -0,0 +1,13 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +resources: + schemas: + schema1: + catalog_name: main + name: test-schema-$UNIQUE_NAME + registered_models: + model1: + catalog_name: main + schema_name: ${resources.schemas.schema1.name} + name: mymodel diff --git a/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/out.test.toml b/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/out.test.toml new file mode 100644 index 00000000000..0f167effef1 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/output.txt b/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/output.txt new file mode 100644 index 00000000000..7412e7de1a0 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/output.txt @@ -0,0 +1,67 @@ + +=== Deploy a schema with a registered model in it + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Created registered_models.model1 +Created schemas.schema1 +Files: 2 uploaded, 0 deleted +Resources: 2 created, 0 changed, 0 deleted, 0 unchanged + +=== Rename the schema out of band. UC moves the model with it + +>>> [CLI] schemas update main.test-schema-[UNIQUE_NAME] --new-name test-schema-renamed-[UNIQUE_NAME] +{ + "full_name": "main.test-schema-renamed-[UNIQUE_NAME]" +} + +=== With the config renamed to match, the plan finds the schema by its schema_id. A model has no such id, so the plan creates it again + +>>> update_file.py databricks.yml test-schema- test-schema-renamed- + +>>> [CLI] bundle plan +create registered_models.model1 + +Plan: 1 to add, 0 to change, 0 to delete, 1 unchanged + +=== The create fails: the model is already there + +>>> errcode [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Error: cannot create resources.registered_models.model1: Routine or Model 'mymodel' already exists (400 RESOURCE_ALREADY_EXISTS) + +Endpoint: POST [DATABRICKS_URL]/api/2.1/unity-catalog/models +HTTP Status: 400 Bad Request +API error_code: RESOURCE_ALREADY_EXISTS +API message: Routine or Model 'mymodel' already exists + +Files: 3 uploaded, 0 deleted + +Exit code: 1 + +>>> print_requests.py //unity-catalog +{ + "method": "POST", + "path": "/api/2.1/unity-catalog/models", + "body": { + "catalog_name": "main", + "name": "mymodel", + "schema_name": "test-schema-renamed-[UNIQUE_NAME]" + } +} + +>>> [CLI] registered-models get main.test-schema-renamed-[UNIQUE_NAME].mymodel +{ + "full_name": "main.test-schema-renamed-[UNIQUE_NAME].mymodel" +} + +>>> [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/registered_models/parent_rename_out_of_band/script b/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/script new file mode 100644 index 00000000000..bbd254c0797 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/script @@ -0,0 +1,29 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +OLD_SCHEMA="main.test-schema-${UNIQUE_NAME}" +NEW_SCHEMA="main.test-schema-renamed-${UNIQUE_NAME}" + +cleanup() { + trace $CLI bundle destroy --auto-approve + + # 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 with a registered model in it" +trace $CLI bundle deploy +print_requests.py //unity-catalog &> LOG.deploy_requests + +title "Rename the schema out of band. UC moves the model with it" +trace $CLI schemas update "$OLD_SCHEMA" --new-name "test-schema-renamed-${UNIQUE_NAME}" | jq '{full_name}' +print_requests.py //unity-catalog &> LOG.rename_requests + +title "With the config renamed to match, the plan finds the schema by its schema_id. A model has no such id, so the plan creates it again" +trace update_file.py databricks.yml test-schema- test-schema-renamed- +trace $CLI bundle plan + +title "The create fails: the model is already there" +trace errcode $CLI bundle deploy +trace print_requests.py //unity-catalog +trace $CLI registered-models get "$NEW_SCHEMA.mymodel" | jq '{full_name}' diff --git a/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/test.toml b/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/test.toml new file mode 100644 index 00000000000..e1372ecbad3 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/test.toml @@ -0,0 +1,8 @@ +Cloud = true +Badness = "The plan does not look for a model whose schema was renamed outside the bundle (a model has no recorded id to find it by), so it creates it again: the create fails with RESOURCE_ALREADY_EXISTS on every deploy. Same on main." + +Ignore = [ + ".databricks", + ".gitignore", + "databricks.yml", +] From 958a9946f0c92f32eff21b0cd64dc5bced5f3b96 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 16 Nov 2026 14:46:33 +0100 Subject: [PATCH 30/44] acc: a model whose schema rename is interrupted is created again (Badness) Co-authored-by: Isaac --- .../databricks.yml.tmpl | 14 ++ .../parent_rename_interrupted/out.test.toml | 2 + .../parent_rename_interrupted/output.txt | 166 ++++++++++++++++++ .../parent_rename_interrupted/script | 36 ++++ .../parent_rename_interrupted/test.toml | 37 ++++ 5 files changed, 255 insertions(+) create mode 100644 acceptance/bundle/resources/registered_models/parent_rename_interrupted/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/registered_models/parent_rename_interrupted/out.test.toml create mode 100644 acceptance/bundle/resources/registered_models/parent_rename_interrupted/output.txt create mode 100644 acceptance/bundle/resources/registered_models/parent_rename_interrupted/script create mode 100644 acceptance/bundle/resources/registered_models/parent_rename_interrupted/test.toml diff --git a/acceptance/bundle/resources/registered_models/parent_rename_interrupted/databricks.yml.tmpl b/acceptance/bundle/resources/registered_models/parent_rename_interrupted/databricks.yml.tmpl new file mode 100644 index 00000000000..6f739c9c6c5 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/parent_rename_interrupted/databricks.yml.tmpl @@ -0,0 +1,14 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +resources: + schemas: + schema1: + catalog_name: main + name: test-schema-$UNIQUE_NAME + registered_models: + model1: + catalog_name: main + schema_name: ${resources.schemas.schema1.name} + name: mymodel + comment: c1 diff --git a/acceptance/bundle/resources/registered_models/parent_rename_interrupted/out.test.toml b/acceptance/bundle/resources/registered_models/parent_rename_interrupted/out.test.toml new file mode 100644 index 00000000000..19b5b15d11f --- /dev/null +++ b/acceptance/bundle/resources/registered_models/parent_rename_interrupted/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/resources/registered_models/parent_rename_interrupted/output.txt b/acceptance/bundle/resources/registered_models/parent_rename_interrupted/output.txt new file mode 100644 index 00000000000..621b9af296a --- /dev/null +++ b/acceptance/bundle/resources/registered_models/parent_rename_interrupted/output.txt @@ -0,0 +1,166 @@ + +=== Deploy a schema with a registered model in it + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Created registered_models.model1 +Created schemas.schema1 +Files: 2 uploaded, 0 deleted +Resources: 2 created, 0 changed, 0 deleted, 0 unchanged + +=== Rename the schema and change the model's comment. The CLI is killed on the model's update, after the schema's rename is saved + +>>> update_file.py databricks.yml test-schema- test-schema-renamed- + +>>> update_file.py databricks.yml comment: c1 comment: c2 + +>>> errcode [CLI] bundle deploy -q +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +[PROCESS_KILLED] + +Exit code: [KILLED] + +>>> print_requests.py //unity-catalog +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/schemas/main.test-schema-[UNIQUE_NAME]", + "body": { + "comment": "", + "custom_max_retention_hours": 0, + "new_name": "test-schema-renamed-[UNIQUE_NAME]" + } +} + +=== The model is gone from its recorded path. A model has no recorded id, so the plan does not find it at its new path and creates it again + +>>> print_state.py +{ + "__id__": "main.test-schema-[UNIQUE_NAME].mymodel" +} + +>>> [CLI] bundle plan --output json +{ + "resources.registered_models.model1": { + "depends_on": [ + { + "node": "resources.schemas.schema1", + "label": "${resources.schemas.schema1.name}" + } + ], + "action": "create", + "new_state": { + "value": { + "catalog_name": "main", + "comment": "c2", + "name": "mymodel", + "schema_name": "test-schema-renamed-[UNIQUE_NAME]" + } + }, + "changes": { + "comment": { + "action": "update", + "old": "c1", + "new": "c2" + }, + "schema_name": { + "action": "recreate", + "reason": "id_field", + "old": "test-schema-[UNIQUE_NAME]", + "new": "test-schema-renamed-[UNIQUE_NAME]" + } + } + }, + "resources.schemas.schema1": { + "action": "skip", + "remote_state": { + "browse_only": false, + "catalog_name": "main", + "catalog_type": "MANAGED_CATALOG", + "comment": "", + "created_by": "[USERNAME]", + "custom_max_retention_hours": 0, + "effective_predictive_optimization_flag": { + "inherited_from_name": "[METASTORE_NAME]", + "inherited_from_type": "METASTORE", + "value": "ENABLE" + }, + "enable_predictive_optimization": "INHERIT", + "full_name": "main.test-schema-renamed-[UNIQUE_NAME]", + "metastore_id": "[UUID][0]", + "name": "test-schema-renamed-[UNIQUE_NAME]", + "owner": "[USERNAME]", + "schema_id": "[UUID][1]", + "updated_by": "[USERNAME]" + }, + "changes": { + "comment": { + "action": "skip", + "reason": "empty", + "remote": "" + }, + "custom_max_retention_hours": { + "action": "skip", + "reason": "empty", + "remote": 0 + }, + "schema_id": { + "action": "skip", + "reason": "internal_id", + "old": "[UUID][1]", + "remote": "[UUID][1]" + } + } + } +} + +=== The create fails: the model is already there + +>>> errcode [CLI] bundle deploy --force-lock +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Error: cannot create resources.registered_models.model1: Routine or Model 'mymodel' already exists (400 RESOURCE_ALREADY_EXISTS) + +Endpoint: POST [DATABRICKS_URL]/api/2.1/unity-catalog/models +HTTP Status: 400 Bad Request +API error_code: RESOURCE_ALREADY_EXISTS +API message: Routine or Model 'mymodel' already exists + +Files: 0 uploaded, 0 deleted + +Exit code: 1 + +>>> print_requests.py //unity-catalog +{ + "method": "POST", + "path": "/api/2.1/unity-catalog/models", + "body": { + "catalog_name": "main", + "comment": "c2", + "name": "mymodel", + "schema_name": "test-schema-renamed-[UNIQUE_NAME]" + } +} + +>>> [CLI] registered-models get main.test-schema-renamed-[UNIQUE_NAME].mymodel +{ + "full_name": "main.test-schema-renamed-[UNIQUE_NAME].mymodel", + "comment": "c1", + "created_at": [MODEL_CREATED_AT] +} + +=== The next plan creates it again + +>>> [CLI] bundle plan +create registered_models.model1 + +Plan: 1 to add, 0 to change, 0 to delete, 1 unchanged + +>>> [CLI] bundle destroy --auto-approve --force-lock +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/registered_models/parent_rename_interrupted/script b/acceptance/bundle/resources/registered_models/parent_rename_interrupted/script new file mode 100644 index 00000000000..3c2f3fc40f9 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/parent_rename_interrupted/script @@ -0,0 +1,36 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +NEW_MODEL="main.test-schema-renamed-${UNIQUE_NAME}.mymodel" + +cleanup() { + trace $CLI bundle destroy --auto-approve --force-lock + + # 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 with a registered model in it" +trace $CLI bundle deploy +print_requests.py //unity-catalog &> LOG.deploy_requests +add_repl "$($CLI registered-models get "main.test-schema-${UNIQUE_NAME}.mymodel" | jq -r .created_at)" MODEL_CREATED_AT + +title "Rename the schema and change the model's comment. The CLI is killed on the model's update, after the schema's rename is saved" +trace update_file.py databricks.yml test-schema- test-schema-renamed- +trace update_file.py databricks.yml "comment: c1" "comment: c2" +kill_after.py "PATCH /api/2.1/unity-catalog/models/$NEW_MODEL" 0 1 +# -q: the per-resource lines race the kill signal. +trace errcode $CLI bundle deploy -q +trace print_requests.py //unity-catalog + +title "The model is gone from its recorded path. A model has no recorded id, so the plan does not find it at its new path and creates it again" +trace print_state.py | jq '.state["resources.registered_models.model1"] | {__id__}' +trace $CLI bundle plan --output json | jq .plan | normalize_uc_payload.py created_at updated_at + +title "The create fails: the model is already there" +trace errcode $CLI bundle deploy --force-lock +trace print_requests.py //unity-catalog +trace $CLI registered-models get "$NEW_MODEL" | jq '{full_name, comment, created_at}' + +title "The next plan creates it again" +trace $CLI bundle plan diff --git a/acceptance/bundle/resources/registered_models/parent_rename_interrupted/test.toml b/acceptance/bundle/resources/registered_models/parent_rename_interrupted/test.toml new file mode 100644 index 00000000000..b2ffda10bfd --- /dev/null +++ b/acceptance/bundle/resources/registered_models/parent_rename_interrupted/test.toml @@ -0,0 +1,37 @@ +Badness = "A model has no recorded id, so after a deploy is interrupted between its schema's rename and its own update, the plan does not find it at its new path: it creates it again and the create fails with RESOURCE_ALREADY_EXISTS on every deploy. Main has the same gap when the deploy is interrupted before the model's recreate." + +# Local-only: the test server kills the CLI mid-deploy (kill_after.py), which a real workspace cannot. +Cloud = false + +Ignore = [ + ".databricks", + ".gitignore", + "databricks.yml", +] + +# KillCaller needs the CLI's pid. A kill leaves no state in DMS to recover from, so DMS is not run. +Env.DATABRICKS_CLI_TEST_PID = "1" +EnvMatrix.DMS = [""] + +# Normalize how a killed process shows up on each OS, as in bundle/deploy/wal. +[[Repls]] +Old = 'script: line \d+:\s+\d+ Killed(: 9)?\s+"\$@"' +New = '[PROCESS_KILLED]' + +[[Repls]] +Old = '(\n>>> errcode [^\n]+\n)\nExit code:' +New = "${1}[PROCESS_KILLED]\n\nExit code:" + +[[Repls]] +Old = 'Exit code: 137' +New = 'Exit code: [KILLED]' + +[[Repls]] +Old = '(\[PROCESS_KILLED\]\n\nExit code: )1' +New = '${1}[KILLED]' + +# On Windows a killed CLI leaves no bash "Killed" line. The kill lands right after the +# "Uploading bundle files" line, so it is followed directly by "Exit code: 1". +[[Repls]] +Old = '(Uploading bundle files to [^\n]+)\n\nExit code: 1' +New = "${1}\n[PROCESS_KILLED]\n\nExit code: [KILLED]" From 01df6cee6f42f31e9ceb3dcde55f24f9f1fdacbf Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 17 Nov 2026 12:31:34 +0100 Subject: [PATCH 31/44] testserver: reject renaming a registered model onto a taken name, as UC does (review F1) Verified on AWS, Azure and GCP: 400 RESOURCE_ALREADY_EXISTS "Routine or Model '' already exists". A missing model on update now gets the same UC error as on get. Co-authored-by: Isaac --- libs/testserver/registered_models.go | 33 ++++++++++++++--------- libs/testserver/registered_models_test.go | 19 +++++++++++++ 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/libs/testserver/registered_models.go b/libs/testserver/registered_models.go index 908ed0b09c7..c41436713e5 100644 --- a/libs/testserver/registered_models.go +++ b/libs/testserver/registered_models.go @@ -28,15 +28,8 @@ func (s *FakeWorkspace) RegisteredModelsCreate(req Request) Response { // Build full name from catalog.schema.name fullName := createRequest.CatalogName + "." + createRequest.SchemaName + "." + createRequest.Name - // UC names the model by its short name here (verified on AWS). if _, ok := s.RegisteredModels[fullName]; ok { - return Response{ - StatusCode: http.StatusBadRequest, - Body: map[string]string{ - "error_code": "RESOURCE_ALREADY_EXISTS", - "message": fmt.Sprintf("Routine or Model '%s' already exists", createRequest.Name), - }, - } + return registeredModelAlreadyExists(createRequest.Name) } registeredModel := catalog.RegisteredModelInfo{ @@ -69,10 +62,7 @@ func (s *FakeWorkspace) RegisteredModelsUpdate(req Request, fullName string) Res existing, ok := s.RegisteredModels[fullName] if !ok { - return Response{ - StatusCode: http.StatusNotFound, - Body: fmt.Sprintf("registered model %s not found", fullName), - } + return registeredModelNotFound(fullName) } fields, errResponse := parseUpdateFields(req.Body) @@ -98,6 +88,13 @@ func (s *FakeWorkspace) RegisteredModelsUpdate(req Request, fullName string) Res } } + if updateRequest.NewName != "" { + newFullName := existing.CatalogName + "." + existing.SchemaName + "." + updateRequest.NewName + if _, taken := s.RegisteredModels[newFullName]; taken && newFullName != fullName { + return registeredModelAlreadyExists(updateRequest.NewName) + } + } + // The update API ignores aliases; they are set through the alias endpoints. delete(fields, "aliases") applyUpdatedFields(&existing, updateRequest, fields) @@ -250,6 +247,18 @@ func (s *FakeWorkspace) RegisteredModelsDeleteAlias(fullName, aliasName string) return Response{} } +// registeredModelAlreadyExists is UC's answer to a create or rename onto a taken name; it names the +// model by its short name (verified on AWS). +func registeredModelAlreadyExists(name string) Response { + return Response{ + StatusCode: http.StatusBadRequest, + Body: map[string]string{ + "error_code": "RESOURCE_ALREADY_EXISTS", + "message": fmt.Sprintf("Routine or Model '%s' already exists", name), + }, + } +} + func registeredModelNotFound(fullName string) Response { return Response{ StatusCode: http.StatusNotFound, diff --git a/libs/testserver/registered_models_test.go b/libs/testserver/registered_models_test.go index 81f955ebc1f..835f90e0959 100644 --- a/libs/testserver/registered_models_test.go +++ b/libs/testserver/registered_models_test.go @@ -23,3 +23,22 @@ func TestRegisteredModelsCreate_RejectsExistingModel(t *testing.T) { // The existing model is kept as it was. assert.Equal(t, "first", workspace.RegisteredModels["main.default.mymodel"].Comment) } + +func TestRegisteredModelsUpdate_RejectsRenameOntoExistingModel(t *testing.T) { + workspace := NewFakeWorkspace("http://test", "dbapi123") + for _, name := range []string{"model_a", "model_b"} { + body := `{"catalog_name": "main", "schema_name": "default", "name": "` + name + `"}` + require.Equal(t, 0, workspace.RegisteredModelsCreate(Request{Body: []byte(body)}).StatusCode) + } + + response := workspace.RegisteredModelsUpdate(Request{Body: []byte(`{"new_name": "model_b"}`)}, "main.default.model_a") + assert.Equal(t, 400, response.StatusCode) + assert.Equal(t, map[string]string{ + "error_code": "RESOURCE_ALREADY_EXISTS", + "message": "Routine or Model 'model_b' already exists", + }, response.Body) + + // Both models are kept as they were. + assert.Contains(t, workspace.RegisteredModels, "main.default.model_a") + assert.Contains(t, workspace.RegisteredModels, "main.default.model_b") +} From 8300b8e243952c08af75076c90445ba2735ec069 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 17 Nov 2026 12:31:35 +0100 Subject: [PATCH 32/44] acc: renaming a registered model onto a taken name fails and keeps both (review F1) Co-authored-by: Isaac --- .../databricks.yml.tmpl | 17 +++++ .../rename_to_existing_name/out.test.toml | 2 + .../rename_to_existing_name/output.txt | 62 +++++++++++++++++++ .../rename_to_existing_name/script | 24 +++++++ .../rename_to_existing_name/test.toml | 7 +++ 5 files changed, 112 insertions(+) create mode 100644 acceptance/bundle/resources/registered_models/rename_to_existing_name/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/registered_models/rename_to_existing_name/out.test.toml create mode 100644 acceptance/bundle/resources/registered_models/rename_to_existing_name/output.txt create mode 100644 acceptance/bundle/resources/registered_models/rename_to_existing_name/script create mode 100644 acceptance/bundle/resources/registered_models/rename_to_existing_name/test.toml diff --git a/acceptance/bundle/resources/registered_models/rename_to_existing_name/databricks.yml.tmpl b/acceptance/bundle/resources/registered_models/rename_to_existing_name/databricks.yml.tmpl new file mode 100644 index 00000000000..90d305eff4d --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_to_existing_name/databricks.yml.tmpl @@ -0,0 +1,17 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +resources: + schemas: + schema1: + catalog_name: main + name: test-schema-$UNIQUE_NAME + registered_models: + model1: + catalog_name: main + schema_name: ${resources.schemas.schema1.name} + name: model_a + model2: + catalog_name: main + schema_name: ${resources.schemas.schema1.name} + name: model_b diff --git a/acceptance/bundle/resources/registered_models/rename_to_existing_name/out.test.toml b/acceptance/bundle/resources/registered_models/rename_to_existing_name/out.test.toml new file mode 100644 index 00000000000..0f167effef1 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_to_existing_name/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/registered_models/rename_to_existing_name/output.txt b/acceptance/bundle/resources/registered_models/rename_to_existing_name/output.txt new file mode 100644 index 00000000000..ec8a113e5a2 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_to_existing_name/output.txt @@ -0,0 +1,62 @@ + +=== Deploy a schema with two registered models + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Created registered_models.model1 +Created registered_models.model2 +Created schemas.schema1 +Files: 2 uploaded, 0 deleted +Resources: 3 created, 0 changed, 0 deleted, 0 unchanged + +=== Rename the first model to the second one's name: UC rejects the rename + +>>> update_file.py databricks.yml name: model_a name: model_b + +>>> musterr [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Error: cannot update_id resources.registered_models.model1: updating id=main.test-schema-[UNIQUE_NAME].model_a: Routine or Model 'model_b' already exists (400 RESOURCE_ALREADY_EXISTS) + +Endpoint: PATCH [DATABRICKS_URL]/api/2.1/unity-catalog/models/main.test-schema-[UNIQUE_NAME].model_a +HTTP Status: 400 Bad Request +API error_code: RESOURCE_ALREADY_EXISTS +API message: Routine or Model 'model_b' already exists + +Files: 2 uploaded, 0 deleted + +>>> print_requests.py //unity-catalog +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/models/main.test-schema-[UNIQUE_NAME].model_a", + "body": { + "catalog_name": "main", + "comment": "", + "new_name": "model_b", + "schema_name": "test-schema-[UNIQUE_NAME]" + } +} + +=== Both models are still there under their names + +>>> [CLI] registered-models get main.test-schema-[UNIQUE_NAME].model_a +{ + "full_name": "main.test-schema-[UNIQUE_NAME].model_a" +} + +>>> [CLI] registered-models get main.test-schema-[UNIQUE_NAME].model_b +{ + "full_name": "main.test-schema-[UNIQUE_NAME].model_b" +} + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.registered_models.model1 + delete resources.registered_models.model2 + 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: 3 deleted diff --git a/acceptance/bundle/resources/registered_models/rename_to_existing_name/script b/acceptance/bundle/resources/registered_models/rename_to_existing_name/script new file mode 100644 index 00000000000..404e86e9aa9 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_to_existing_name/script @@ -0,0 +1,24 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +SCHEMA="main.test-schema-${UNIQUE_NAME}" + +cleanup() { + trace $CLI bundle destroy --auto-approve + + # 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 with two registered models" +trace $CLI bundle deploy +print_requests.py //unity-catalog &> LOG.deploy_requests + +title "Rename the first model to the second one's name: UC rejects the rename" +trace update_file.py databricks.yml "name: model_a" "name: model_b" +trace musterr $CLI bundle deploy +trace print_requests.py //unity-catalog + +title "Both models are still there under their names" +trace $CLI registered-models get "$SCHEMA.model_a" | jq '{full_name}' +trace $CLI registered-models get "$SCHEMA.model_b" | jq '{full_name}' diff --git a/acceptance/bundle/resources/registered_models/rename_to_existing_name/test.toml b/acceptance/bundle/resources/registered_models/rename_to_existing_name/test.toml new file mode 100644 index 00000000000..4272a80cf61 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_to_existing_name/test.toml @@ -0,0 +1,7 @@ +Cloud = true + +Ignore = [ + ".databricks", + ".gitignore", + "databricks.yml", +] From b8fc46a153531fb53e96ff72b33f584ee90c0d5e Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 17 Nov 2026 12:31:43 +0100 Subject: [PATCH 33/44] direct: sync a model's aliases before renaming it (review R1) A failed alias sync after the rename left the state at the old name, and the next deploy looked for a model that no longer existed there. Aliases now go first, under the current name. Co-authored-by: Isaac --- bundle/direct/dresources/registered_model.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/bundle/direct/dresources/registered_model.go b/bundle/direct/dresources/registered_model.go index 81a88db5dd2..14273dac6c7 100644 --- a/bundle/direct/dresources/registered_model.go +++ b/bundle/direct/dresources/registered_model.go @@ -145,21 +145,27 @@ func (r *ResourceRegisteredModel) DoUpdateWithID(ctx context.Context, id string, return "", nil, err } - // The catalog and schema come from config: a renamed parent moves the model with it, leaving id - // stale (see followsParentRename). - parent := config.CatalogName + "." + config.SchemaName + "." - newID := parent + config.Name + // The catalog and schema come from config: a renamed parent moves the model with it (see + // followsParentRename). + current := config.CatalogName + "." + config.SchemaName + "." + nameFromID + + // Aliases go first, under the current name: if they fail, the model is not renamed yet, so the + // state still points at it. + err = r.syncChangedAliases(ctx, current, config, entry) + if err != nil { + return "", nil, err + } newName := "" if config.Name != nameFromID { newName = config.Name } - response, err := r.client.RegisteredModels.Update(ctx, makeUpdateRegisteredModel(parent+nameFromID, newName, config)) + response, err := r.client.RegisteredModels.Update(ctx, makeUpdateRegisteredModel(current, newName, config)) if err != nil { return "", nil, err } - return newID, response, r.syncChangedAliases(ctx, newID, config, entry) + return config.CatalogName + "." + config.SchemaName + "." + config.Name, response, nil } // syncChangedAliases applies the configured aliases when the plan changes them. From a4abed98d61f25bfda9e289ffd3f6d22700d9ab8 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 17 Nov 2026 12:31:49 +0100 Subject: [PATCH 34/44] direct: take a renamed model's ID from the response, like create does (review F2) Co-authored-by: Isaac --- bundle/direct/dresources/registered_model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/direct/dresources/registered_model.go b/bundle/direct/dresources/registered_model.go index 14273dac6c7..0186db9ae61 100644 --- a/bundle/direct/dresources/registered_model.go +++ b/bundle/direct/dresources/registered_model.go @@ -165,7 +165,7 @@ func (r *ResourceRegisteredModel) DoUpdateWithID(ctx context.Context, id string, if err != nil { return "", nil, err } - return config.CatalogName + "." + config.SchemaName + "." + config.Name, response, nil + return response.FullName, response, nil } // syncChangedAliases applies the configured aliases when the plan changes them. From 9d7be0d475c2edff974e50eda60bcb536954724e Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 17 Nov 2026 12:31:51 +0100 Subject: [PATCH 35/44] direct: record the ID a parent's rename moved a resource to before updating it there (review S2) The parent is applied first, so the move has already happened. A failed or interrupted update left the state at the old ID, and a resource with no internal ID (a model, a secret) could not be found at its new one: every later deploy failed with ALREADY_EXISTS. This fixes the parent_rename_interrupted Badness. Co-authored-by: Isaac --- .../parent_rename_interrupted/output.txt | 90 +++++++++++-------- .../parent_rename_interrupted/script | 9 +- .../parent_rename_interrupted/test.toml | 2 - bundle/direct/apply.go | 60 ++++++++++++- bundle/direct/apply_test.go | 3 +- 5 files changed, 119 insertions(+), 45 deletions(-) diff --git a/acceptance/bundle/resources/registered_models/parent_rename_interrupted/output.txt b/acceptance/bundle/resources/registered_models/parent_rename_interrupted/output.txt index 621b9af296a..a8d0a2cb96a 100644 --- a/acceptance/bundle/resources/registered_models/parent_rename_interrupted/output.txt +++ b/acceptance/bundle/resources/registered_models/parent_rename_interrupted/output.txt @@ -31,12 +31,7 @@ Exit code: [KILLED] } } -=== The model is gone from its recorded path. A model has no recorded id, so the plan does not find it at its new path and creates it again - ->>> print_state.py -{ - "__id__": "main.test-schema-[UNIQUE_NAME].mymodel" -} +=== The model's new path was recorded before its update, so the plan updates it there >>> [CLI] bundle plan --output json { @@ -47,7 +42,7 @@ Exit code: [KILLED] "label": "${resources.schemas.schema1.name}" } ], - "action": "create", + "action": "update", "new_state": { "value": { "catalog_name": "main", @@ -56,17 +51,48 @@ Exit code: [KILLED] "schema_name": "test-schema-renamed-[UNIQUE_NAME]" } }, + "remote_state": { + "catalog_name": "main", + "comment": "c1", + "created_by": "[USERNAME]", + "full_name": "main.test-schema-renamed-[UNIQUE_NAME].mymodel", + "metastore_id": "[UUID][0]", + "name": "mymodel", + "owner": "[USERNAME]", + "schema_name": "test-schema-renamed-[UNIQUE_NAME]", + "updated_by": "[USERNAME]" + }, "changes": { "comment": { "action": "update", "old": "c1", - "new": "c2" + "new": "c2", + "remote": "c1" }, - "schema_name": { - "action": "recreate", - "reason": "id_field", - "old": "test-schema-[UNIQUE_NAME]", - "new": "test-schema-renamed-[UNIQUE_NAME]" + "created_by": { + "action": "skip", + "reason": "output_only", + "remote": "[USERNAME]" + }, + "full_name": { + "action": "skip", + "reason": "backend_default", + "remote": "main.test-schema-renamed-[UNIQUE_NAME].mymodel" + }, + "metastore_id": { + "action": "skip", + "reason": "backend_default", + "remote": "[UUID][0]" + }, + "owner": { + "action": "skip", + "reason": "backend_default", + "remote": "[USERNAME]" + }, + "updated_by": { + "action": "skip", + "reason": "output_only", + "remote": "[USERNAME]" } } }, @@ -86,10 +112,10 @@ Exit code: [KILLED] }, "enable_predictive_optimization": "INHERIT", "full_name": "main.test-schema-renamed-[UNIQUE_NAME]", - "metastore_id": "[UUID][0]", + "metastore_id": "[UUID][1]", "name": "test-schema-renamed-[UNIQUE_NAME]", "owner": "[USERNAME]", - "schema_id": "[UUID][1]", + "schema_id": "[UUID][2]", "updated_by": "[USERNAME]" }, "changes": { @@ -106,32 +132,25 @@ Exit code: [KILLED] "schema_id": { "action": "skip", "reason": "internal_id", - "old": "[UUID][1]", - "remote": "[UUID][1]" + "old": "[UUID][2]", + "remote": "[UUID][2]" } } } } -=== The create fails: the model is already there +=== The next deploy updates the model at its new path ->>> errcode [CLI] bundle deploy --force-lock +>>> [CLI] bundle deploy --force-lock Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... -Error: cannot create resources.registered_models.model1: Routine or Model 'mymodel' already exists (400 RESOURCE_ALREADY_EXISTS) - -Endpoint: POST [DATABRICKS_URL]/api/2.1/unity-catalog/models -HTTP Status: 400 Bad Request -API error_code: RESOURCE_ALREADY_EXISTS -API message: Routine or Model 'mymodel' already exists - +Updated registered_models.model1 Files: 0 uploaded, 0 deleted - -Exit code: 1 +Resources: 0 created, 1 changed, 0 deleted, 1 unchanged >>> print_requests.py //unity-catalog { - "method": "POST", - "path": "/api/2.1/unity-catalog/models", + "method": "PATCH", + "path": "/api/2.1/unity-catalog/models/main.test-schema-renamed-[UNIQUE_NAME].mymodel", "body": { "catalog_name": "main", "comment": "c2", @@ -143,19 +162,18 @@ Exit code: 1 >>> [CLI] registered-models get main.test-schema-renamed-[UNIQUE_NAME].mymodel { "full_name": "main.test-schema-renamed-[UNIQUE_NAME].mymodel", - "comment": "c1", + "comment": "c2", "created_at": [MODEL_CREATED_AT] } -=== The next plan creates it again +=== Redeploy is a no-op >>> [CLI] bundle plan -create registered_models.model1 - -Plan: 1 to add, 0 to change, 0 to delete, 1 unchanged +Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged >>> [CLI] bundle destroy --auto-approve --force-lock The following resources will be deleted: + delete resources.registered_models.model1 delete resources.schemas.schema1 This action will result in the deletion of the following UC schemas. Any underlying data may be lost: @@ -163,4 +181,4 @@ This action will result in the deletion of the following UC schemas. Any underly All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default -Destroy: 1 deleted +Destroy: 2 deleted diff --git a/acceptance/bundle/resources/registered_models/parent_rename_interrupted/script b/acceptance/bundle/resources/registered_models/parent_rename_interrupted/script index 3c2f3fc40f9..4423e4b28cd 100644 --- a/acceptance/bundle/resources/registered_models/parent_rename_interrupted/script +++ b/acceptance/bundle/resources/registered_models/parent_rename_interrupted/script @@ -23,14 +23,13 @@ kill_after.py "PATCH /api/2.1/unity-catalog/models/$NEW_MODEL" 0 1 trace errcode $CLI bundle deploy -q trace print_requests.py //unity-catalog -title "The model is gone from its recorded path. A model has no recorded id, so the plan does not find it at its new path and creates it again" -trace print_state.py | jq '.state["resources.registered_models.model1"] | {__id__}' +title "The model's new path was recorded before its update, so the plan updates it there" trace $CLI bundle plan --output json | jq .plan | normalize_uc_payload.py created_at updated_at -title "The create fails: the model is already there" -trace errcode $CLI bundle deploy --force-lock +title "The next deploy updates the model at its new path" +trace $CLI bundle deploy --force-lock trace print_requests.py //unity-catalog trace $CLI registered-models get "$NEW_MODEL" | jq '{full_name, comment, created_at}' -title "The next plan creates it again" +title "Redeploy is a no-op" trace $CLI bundle plan diff --git a/acceptance/bundle/resources/registered_models/parent_rename_interrupted/test.toml b/acceptance/bundle/resources/registered_models/parent_rename_interrupted/test.toml index b2ffda10bfd..443e541f555 100644 --- a/acceptance/bundle/resources/registered_models/parent_rename_interrupted/test.toml +++ b/acceptance/bundle/resources/registered_models/parent_rename_interrupted/test.toml @@ -1,5 +1,3 @@ -Badness = "A model has no recorded id, so after a deploy is interrupted between its schema's rename and its own update, the plan does not find it at its new path: it creates it again and the create fails with RESOURCE_ALREADY_EXISTS on every deploy. Main has the same gap when the deploy is interrupted before the model's recreate." - # Local-only: the test server kills the CLI mid-deploy (kill_after.py), which a real workspace cannot. Cloud = false diff --git a/bundle/direct/apply.go b/bundle/direct/apply.go index 2683c6c1532..b8038d1c906 100644 --- a/bundle/direct/apply.go +++ b/bundle/direct/apply.go @@ -13,6 +13,8 @@ import ( "github.com/databricks/cli/bundle/direct/dstate" "github.com/databricks/cli/libs/log" "github.com/databricks/cli/libs/retry" + "github.com/databricks/cli/libs/structs/structaccess" + "github.com/databricks/cli/libs/structs/structpath" "github.com/databricks/databricks-sdk-go/apierr" ) @@ -220,9 +222,14 @@ func (d *DeploymentUnit) Update(ctx context.Context, db *dstate.DeploymentState, } func (d *DeploymentUnit) UpdateWithID(ctx context.Context, db *dstate.DeploymentState, oldID string, newState any, planEntry *deployplan.PlanEntry) error { + oldID, err := d.followParentRename(ctx, db, oldID, newState, planEntry) + if err != nil { + return err + } + var newID string var remoteState any - _, err := retry.With(ctx, retry.IsTransient, func() (struct{}, error) { + _, err = retry.With(ctx, retry.IsTransient, func() (struct{}, error) { var e error newID, remoteState, e = d.Adapter.DoUpdateWithID(ctx, oldID, newState, planEntry) return struct{}{}, e @@ -267,6 +274,57 @@ func (d *DeploymentUnit) UpdateWithID(ctx context.Context, db *dstate.Deployment return nil } +// followParentRename records the resource at the ID its parent's rename moved it to, before the +// update applies the resource's own changes there. The parent is applied first, so the move has +// already happened: if the update then fails, or the deploy is interrupted, the state still points +// at the resource. Without this, the next plan would find nothing at the old ID, and a resource +// with no internal ID could not be found at its new one. It returns the ID to update at. +func (d *DeploymentUnit) followParentRename(ctx context.Context, db *dstate.DeploymentState, oldID string, newState any, planEntry *deployplan.PlanEntry) (string, error) { + var parentPaths []*structpath.PathNode + for pathString, ch := range planEntry.Changes { + if ch.Reason != deployplan.ReasonParentRenamed { + continue + } + path, err := structpath.ParsePath(pathString) + if err != nil { + return "", err + } + parentPaths = append(parentPaths, path) + } + if len(parentPaths) == 0 { + return oldID, nil + } + + // The saved state with the parent fields of the new one: what the resource is after the move. + state, err := d.loadPersistedState(db) + if err != nil { + return "", err + } + for _, path := range parentPaths { + value, err := structaccess.Get(newState, path) + if err != nil { + return "", fmt.Errorf("reading %s: %w", path, err) + } + if err := structaccess.Set(state, path, value); err != nil { + return "", fmt.Errorf("setting %s: %w", path, err) + } + } + movedID, err := d.Adapter.IDFromState(state) + if err != nil { + return "", err + } + if movedID == oldID { + return oldID, nil + } + + log.Infof(ctx, "Re-keyed %s id=%#v (previously %#v) after its parent's rename", d.ResourceKey, movedID, oldID) + err = d.saveState(ctx, db, movedID, state, d.DependsOn, planEntry.RemoteState) + if err != nil { + return "", fmt.Errorf("saving state id=%s: %w", movedID, err) + } + return movedID, nil +} + // Rekey records the resource under the ID its new state gives it, without calling the backend: a // rename already moved it there (see PlanEntry.StateOnly). func (d *DeploymentUnit) Rekey(ctx context.Context, db *dstate.DeploymentState, oldID string, newState any, planEntry *deployplan.PlanEntry) error { diff --git a/bundle/direct/apply_test.go b/bundle/direct/apply_test.go index 24304292ddc..e6415da6475 100644 --- a/bundle/direct/apply_test.go +++ b/bundle/direct/apply_test.go @@ -2,6 +2,7 @@ package direct import ( "context" + "github.com/databricks/cli/bundle/deployplan" "path/filepath" "testing" @@ -80,7 +81,7 @@ func TestUpdateWithIDFailsOnEmptyID(t *testing.T) { d := &DeploymentUnit{ResourceKey: "resources.fakes.foo", Adapter: adapter} require.NoError(t, db.SaveState(t.Context(), d.ResourceKey, "old-id", &emptyIDState{Name: "foo"}, nil)) - err = d.UpdateWithID(t.Context(), db, "old-id", &emptyIDState{Name: "bar"}, nil) + err = d.UpdateWithID(t.Context(), db, "old-id", &emptyIDState{Name: "bar"}, &deployplan.PlanEntry{}) require.EqualError(t, err, "update returned an empty resource id") assert.Equal(t, "old-id", db.GetResourceID(d.ResourceKey)) From 261fc6638b2c9a89ab2e423ff114513f24d32d62 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 17 Nov 2026 12:35:55 +0100 Subject: [PATCH 36/44] acc: a renamed model keeps its versions, and a failed alias leaves it unrenamed (review R1, F3) Local only, like the other alias tests: versions are registered through the test server. Co-authored-by: Isaac --- .../registered_models/rename/output.txt | 2 +- .../resources/registered_models/rename/script | 2 +- .../rename_with_aliases/databricks.yml.tmpl | 10 ++ .../rename_with_aliases/out.test.toml | 2 + .../rename_with_aliases/output.txt | 139 ++++++++++++++++++ .../rename_with_aliases/script | 42 ++++++ .../rename_with_aliases/test.toml | 9 ++ 7 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 acceptance/bundle/resources/registered_models/rename_with_aliases/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/registered_models/rename_with_aliases/out.test.toml create mode 100644 acceptance/bundle/resources/registered_models/rename_with_aliases/output.txt create mode 100644 acceptance/bundle/resources/registered_models/rename_with_aliases/script create mode 100644 acceptance/bundle/resources/registered_models/rename_with_aliases/test.toml diff --git a/acceptance/bundle/resources/registered_models/rename/output.txt b/acceptance/bundle/resources/registered_models/rename/output.txt index dc9bf99b35b..d26ba832ca5 100644 --- a/acceptance/bundle/resources/registered_models/rename/output.txt +++ b/acceptance/bundle/resources/registered_models/rename/output.txt @@ -28,7 +28,7 @@ Resources: 2 created, 0 changed, 0 deleted, 0 unchanged } } -=== Rename the model: it is renamed in place, keeping its versions +=== Rename the model: it is renamed in place, not recreated >>> update_file.py databricks.yml name: mymodel name: mymodel2 diff --git a/acceptance/bundle/resources/registered_models/rename/script b/acceptance/bundle/resources/registered_models/rename/script index b173bf86fe8..4945c5ccd92 100644 --- a/acceptance/bundle/resources/registered_models/rename/script +++ b/acceptance/bundle/resources/registered_models/rename/script @@ -15,7 +15,7 @@ trace $CLI bundle deploy trace print_requests.py //unity-catalog add_repl "$($CLI registered-models get "$SCHEMA.mymodel" | jq -r .created_at)" MODEL_CREATED_AT -title "Rename the model: it is renamed in place, keeping its versions" +title "Rename the model: it is renamed in place, not recreated" trace update_file.py databricks.yml "name: mymodel" "name: mymodel2" # Drop the remote_state fields that differ between clouds or from the test server. trace $CLI bundle plan --output json | tee .databricks/plan.json | jq .plan | normalize_uc_payload.py created_at updated_at updated_by metastore_id browse_only effective_predictive_optimization_flag storage_location diff --git a/acceptance/bundle/resources/registered_models/rename_with_aliases/databricks.yml.tmpl b/acceptance/bundle/resources/registered_models/rename_with_aliases/databricks.yml.tmpl new file mode 100644 index 00000000000..e35701abb3a --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_with_aliases/databricks.yml.tmpl @@ -0,0 +1,10 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +resources: + registered_models: + model1: + catalog_name: main + schema_name: default + name: model-$UNIQUE_NAME + aliases: [] diff --git a/acceptance/bundle/resources/registered_models/rename_with_aliases/out.test.toml b/acceptance/bundle/resources/registered_models/rename_with_aliases/out.test.toml new file mode 100644 index 00000000000..a927a5fbc06 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_with_aliases/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/registered_models/rename_with_aliases/output.txt b/acceptance/bundle/resources/registered_models/rename_with_aliases/output.txt new file mode 100644 index 00000000000..b6089a9e821 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_with_aliases/output.txt @@ -0,0 +1,139 @@ + +=== Deploy a model and register two versions of it out of band + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Created registered_models.model1 +Files: 2 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +>>> register_model_version main.default.model-[UNIQUE_NAME] +1 + +>>> register_model_version main.default.model-[UNIQUE_NAME] +2 + +=== Rename the model and point 'champion' at version 2 in one deploy. The alias is set first, under the current name + +>>> update_file.py databricks.yml name: model- name: model2- + +>>> update_file.py databricks.yml aliases: [] aliases: [{alias_name: champion, version_num: 2}] + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Updated registered_models.model1 +Files: 2 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 0 unchanged + +>>> print_requests.py //unity-catalog +{ + "method": "PUT", + "path": "/api/2.1/unity-catalog/models/main.default.model-[UNIQUE_NAME]/aliases/champion", + "body": { + "version_num": 2 + } +} +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/models/main.default.model-[UNIQUE_NAME]", + "body": { + "catalog_name": "main", + "comment": "", + "new_name": "model2-[UNIQUE_NAME]", + "schema_name": "default" + } +} + +>>> [CLI] registered-models get main.default.model2-[UNIQUE_NAME] --include-aliases +[ + { + "alias_name": "champion", + "version_num": 2 + } +] + +=== The versions moved with the model: the next one registered is version 3 + +>>> register_model_version main.default.model2-[UNIQUE_NAME] +3 + +=== Rename it again and point 'champion' at version 9, which does not exist. The alias fails first, so the model keeps its name + +>>> update_file.py databricks.yml name: model2- name: model3- + +>>> update_file.py databricks.yml version_num: 2 version_num: 9 + +>>> musterr [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Error: cannot update_id resources.registered_models.model1: updating id=main.default.model2-[UNIQUE_NAME]: Model version 9 of registered model main.default.model2-[UNIQUE_NAME] does not exist. (404 RESOURCE_DOES_NOT_EXIST) + +Endpoint: PUT [DATABRICKS_URL]/api/2.1/unity-catalog/models/main.default.model2-[UNIQUE_NAME]/aliases/champion +HTTP Status: 404 Not Found +API error_code: RESOURCE_DOES_NOT_EXIST +API message: Model version 9 of registered model main.default.model2-[UNIQUE_NAME] does not exist. + +Files: 2 uploaded, 0 deleted + +>>> print_requests.py //unity-catalog +{ + "method": "PUT", + "path": "/api/2.1/unity-catalog/models/main.default.model2-[UNIQUE_NAME]/aliases/champion", + "body": { + "version_num": 9 + } +} + +>>> [CLI] registered-models get main.default.model2-[UNIQUE_NAME] +{ + "full_name": "main.default.model2-[UNIQUE_NAME]" +} + +=== With the alias fixed, the next deploy renames the model + +>>> update_file.py databricks.yml version_num: 9 version_num: 1 + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Updated registered_models.model1 +Files: 1 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 0 unchanged + +>>> print_requests.py //unity-catalog +{ + "method": "PUT", + "path": "/api/2.1/unity-catalog/models/main.default.model2-[UNIQUE_NAME]/aliases/champion", + "body": { + "version_num": 1 + } +} +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/models/main.default.model2-[UNIQUE_NAME]", + "body": { + "catalog_name": "main", + "comment": "", + "new_name": "model3-[UNIQUE_NAME]", + "schema_name": "default" + } +} + +>>> [CLI] registered-models get main.default.model3-[UNIQUE_NAME] --include-aliases +[ + { + "alias_name": "champion", + "version_num": 1 + } +] + +=== Redeploy is a no-op + +>>> [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.registered_models.model1 + +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/registered_models/rename_with_aliases/script b/acceptance/bundle/resources/registered_models/rename_with_aliases/script new file mode 100644 index 00000000000..1b3ea62fa66 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_with_aliases/script @@ -0,0 +1,42 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace $CLI bundle destroy --auto-approve + + # Consume the destroy's requests so none are left recorded. + print_requests.py //unity-catalog &> LOG.destroy_requests +} +trap cleanup EXIT + +title "Deploy a model and register two versions of it out of band" +trace $CLI bundle deploy +trace register_model_version "main.default.model-$UNIQUE_NAME" +trace register_model_version "main.default.model-$UNIQUE_NAME" +print_requests.py //unity-catalog &> LOG.deploy_requests + +title "Rename the model and point 'champion' at version 2 in one deploy. The alias is set first, under the current name" +trace update_file.py databricks.yml "name: model-" "name: model2-" +trace update_file.py databricks.yml "aliases: []" "aliases: [{alias_name: champion, version_num: 2}]" +trace $CLI bundle deploy +trace print_requests.py //unity-catalog +trace $CLI registered-models get "main.default.model2-$UNIQUE_NAME" --include-aliases | alias_fields + +title "The versions moved with the model: the next one registered is version 3" +trace register_model_version "main.default.model2-$UNIQUE_NAME" +print_requests.py //unity-catalog &> LOG.register_requests + +title "Rename it again and point 'champion' at version 9, which does not exist. The alias fails first, so the model keeps its name" +trace update_file.py databricks.yml "name: model2-" "name: model3-" +trace update_file.py databricks.yml "version_num: 2" "version_num: 9" +trace musterr $CLI bundle deploy +trace print_requests.py //unity-catalog +trace $CLI registered-models get "main.default.model2-$UNIQUE_NAME" | jq '{full_name}' + +title "With the alias fixed, the next deploy renames the model" +trace update_file.py databricks.yml "version_num: 9" "version_num: 1" +trace $CLI bundle deploy +trace print_requests.py //unity-catalog +trace $CLI registered-models get "main.default.model3-$UNIQUE_NAME" --include-aliases | alias_fields + +title "Redeploy is a no-op" +trace $CLI bundle plan diff --git a/acceptance/bundle/resources/registered_models/rename_with_aliases/test.toml b/acceptance/bundle/resources/registered_models/rename_with_aliases/test.toml new file mode 100644 index 00000000000..ba7a8832919 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_with_aliases/test.toml @@ -0,0 +1,9 @@ +# Local only: aliases need registered model versions, which the test registers through the fake +# server rather than with MLflow. +RecordRequests = true + +Ignore = [ + ".databricks", + ".gitignore", + "databricks.yml", +] From 85c4ecb2f3d603198ac32d78e6527187c0a553bd Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 17 Nov 2026 14:04:53 +0100 Subject: [PATCH 37/44] acc: an interrupted schema rename now updates the volume at its recorded new path (review S2) Co-authored-by: Isaac --- .../schemas/rename_interrupted/output.txt | 18 ++---------------- .../schemas/rename_interrupted/script | 3 +-- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/acceptance/bundle/resources/schemas/rename_interrupted/output.txt b/acceptance/bundle/resources/schemas/rename_interrupted/output.txt index edf4f618ffb..725161c1e8f 100644 --- a/acceptance/bundle/resources/schemas/rename_interrupted/output.txt +++ b/acceptance/bundle/resources/schemas/rename_interrupted/output.txt @@ -31,13 +31,7 @@ Exit code: [KILLED] } } -=== The volume is gone from its recorded path, so the plan looks for it at its path in config - ->>> print_state.py -{ - "__id__": "main.test-schema-[UNIQUE_NAME].myvolume", - "volume_id": "[VOLUME_ID]" -} +=== The volume's new path was recorded before its update, so the plan updates it there >>> [CLI] bundle plan --output json { @@ -83,14 +77,13 @@ Exit code: [KILLED] } }, "resources.volumes.volume1": { - "id": "main.test-schema-renamed-[UNIQUE_NAME].myvolume", "depends_on": [ { "node": "resources.schemas.schema1", "label": "${resources.schemas.schema1.name}" } ], - "action": "update_id", + "action": "update", "new_state": { "value": { "catalog_name": "main", @@ -119,13 +112,6 @@ Exit code: [KILLED] "new": "c2", "remote": "c1" }, - "schema_name": { - "action": "skip", - "reason": "remote_already_set", - "old": "test-schema-[UNIQUE_NAME]", - "new": "test-schema-renamed-[UNIQUE_NAME]", - "remote": "test-schema-renamed-[UNIQUE_NAME]" - }, "storage_location": { "action": "skip", "reason": "immutable_backend_value", diff --git a/acceptance/bundle/resources/schemas/rename_interrupted/script b/acceptance/bundle/resources/schemas/rename_interrupted/script index c829d0dea23..8796dc3e26e 100644 --- a/acceptance/bundle/resources/schemas/rename_interrupted/script +++ b/acceptance/bundle/resources/schemas/rename_interrupted/script @@ -23,8 +23,7 @@ kill_after.py "PATCH /api/2.1/unity-catalog/volumes/$NEW_VOLUME" 0 1 trace errcode $CLI bundle deploy -q trace print_requests.py //unity-catalog -title "The volume is gone from its recorded path, so the plan looks for it at its path in config" -trace print_state.py | jq '.state["resources.volumes.volume1"] | {__id__, volume_id: .state.volume_id}' +title "The volume's new path was recorded before its update, so the plan updates it there" trace $CLI bundle plan --output json | jq .plan | normalize_uc_payload.py created_at updated_at title "The next deploy updates the volume at its new path" From 3e76e42dad1986ebe901e296f7adadfce8bc6772 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 17 Nov 2026 14:04:54 +0100 Subject: [PATCH 38/44] acc: a model named after a renamed schema is renamed in place Co-authored-by: Isaac --- .../rename_referenced_by_name/output.txt | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/acceptance/bundle/resources/schemas/rename_referenced_by_name/output.txt b/acceptance/bundle/resources/schemas/rename_referenced_by_name/output.txt index 7499d0dff65..eb0b3f7f3e7 100644 --- a/acceptance/bundle/resources/schemas/rename_referenced_by_name/output.txt +++ b/acceptance/bundle/resources/schemas/rename_referenced_by_name/output.txt @@ -15,45 +15,42 @@ Resources: 4 created, 0 changed, 0 deleted, 0 unchanged >>> update_file.py databricks.yml test_app_ test_app_renamed_ >>> [CLI] bundle plan -recreate registered_models.model1 +update registered_models.model1 update schemas.app recreate secrets.secret1 -Plan: 2 to add, 1 to change, 2 to delete, 1 unchanged +Plan: 1 to add, 2 to change, 1 to delete, 1 unchanged >>> [CLI] bundle deploy --auto-approve Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... -Recreated registered_models.model1 Recreated secrets.secret1 +Updated registered_models.model1 Updated schemas.app Files: 2 uploaded, 0 deleted -Resources: 2 created, 1 changed, 2 deleted, 1 unchanged +Resources: 1 created, 2 changed, 1 deleted, 1 unchanged >>> print_requests.py --sort //unity-catalog -{ - "method": "DELETE", - "path": "/api/2.1/unity-catalog/models/main.test_shared_[UNIQUE_NAME].test_app_[UNIQUE_NAME]" -} { "method": "DELETE", "path": "/api/2.1/unity-catalog/secrets/main.test_shared_[UNIQUE_NAME].test_app_[UNIQUE_NAME]" } { "method": "PATCH", - "path": "/api/2.1/unity-catalog/schemas/main.test_app_[UNIQUE_NAME]", + "path": "/api/2.1/unity-catalog/models/main.test_shared_[UNIQUE_NAME].test_app_[UNIQUE_NAME]", "body": { + "catalog_name": "main", "comment": "", - "custom_max_retention_hours": 0, - "new_name": "test_app_renamed_[UNIQUE_NAME]" + "new_name": "test_app_renamed_[UNIQUE_NAME]", + "schema_name": "test_shared_[UNIQUE_NAME]" } } { - "method": "POST", - "path": "/api/2.1/unity-catalog/models", + "method": "PATCH", + "path": "/api/2.1/unity-catalog/schemas/main.test_app_[UNIQUE_NAME]", "body": { - "catalog_name": "main", - "name": "test_app_renamed_[UNIQUE_NAME]", - "schema_name": "test_shared_[UNIQUE_NAME]" + "comment": "", + "custom_max_retention_hours": 0, + "new_name": "test_app_renamed_[UNIQUE_NAME]" } } { From 22a8af000326059fd63adedd410bbff9a778e273 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 17 Nov 2026 14:29:32 +0100 Subject: [PATCH 39/44] Group the deployplan import with the other bundle imports Co-authored-by: Isaac --- bundle/direct/apply_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/direct/apply_test.go b/bundle/direct/apply_test.go index e6415da6475..d4261fc35e7 100644 --- a/bundle/direct/apply_test.go +++ b/bundle/direct/apply_test.go @@ -2,10 +2,10 @@ package direct import ( "context" - "github.com/databricks/cli/bundle/deployplan" "path/filepath" "testing" + "github.com/databricks/cli/bundle/deployplan" "github.com/databricks/cli/bundle/direct/dresources" "github.com/databricks/cli/bundle/direct/dstate" "github.com/databricks/cli/libs/structs/structpath" From df291984afa26d35720fb0c96523e710cdba7159 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Fri, 20 Nov 2026 13:56:13 +0100 Subject: [PATCH 40/44] testserver: registered model names are case-insensitive and stored lowercase, as in UC Co-authored-by: Isaac --- libs/testserver/registered_models.go | 56 +++++++++++++---------- libs/testserver/registered_models_test.go | 23 ++++++++++ 2 files changed, 55 insertions(+), 24 deletions(-) diff --git a/libs/testserver/registered_models.go b/libs/testserver/registered_models.go index c41436713e5..3d97d0983b2 100644 --- a/libs/testserver/registered_models.go +++ b/libs/testserver/registered_models.go @@ -6,6 +6,7 @@ import ( "net/http" "slices" "strconv" + "strings" "github.com/databricks/databricks-sdk-go/service/catalog" ) @@ -25,10 +26,11 @@ func (s *FakeWorkspace) RegisteredModelsCreate(req Request) Response { } } - // Build full name from catalog.schema.name + // UC normalizes model names to lowercase. + createRequest.Name = strings.ToLower(createRequest.Name) fullName := createRequest.CatalogName + "." + createRequest.SchemaName + "." + createRequest.Name - if _, ok := s.RegisteredModels[fullName]; ok { + if _, ok := s.RegisteredModels[modelKey(fullName)]; ok { return registeredModelAlreadyExists(createRequest.Name) } @@ -51,7 +53,7 @@ func (s *FakeWorkspace) RegisteredModelsCreate(req Request) Response { registeredModel.BrowseOnly = true } - s.RegisteredModels[fullName] = registeredModel + s.RegisteredModels[modelKey(fullName)] = registeredModel return Response{ Body: registeredModel, } @@ -60,7 +62,7 @@ func (s *FakeWorkspace) RegisteredModelsCreate(req Request) Response { func (s *FakeWorkspace) RegisteredModelsUpdate(req Request, fullName string) Response { defer s.LockUnlock()() - existing, ok := s.RegisteredModels[fullName] + existing, ok := s.RegisteredModels[modelKey(fullName)] if !ok { return registeredModelNotFound(fullName) } @@ -89,8 +91,8 @@ func (s *FakeWorkspace) RegisteredModelsUpdate(req Request, fullName string) Res } if updateRequest.NewName != "" { - newFullName := existing.CatalogName + "." + existing.SchemaName + "." + updateRequest.NewName - if _, taken := s.RegisteredModels[newFullName]; taken && newFullName != fullName { + newFullName := existing.CatalogName + "." + existing.SchemaName + "." + strings.ToLower(updateRequest.NewName) + if _, taken := s.RegisteredModels[modelKey(newFullName)]; taken && modelKey(newFullName) != modelKey(fullName) { return registeredModelAlreadyExists(updateRequest.NewName) } } @@ -100,7 +102,7 @@ func (s *FakeWorkspace) RegisteredModelsUpdate(req Request, fullName string) Res applyUpdatedFields(&existing, updateRequest, fields) if updateRequest.NewName != "" { - existing.Name = updateRequest.NewName + existing.Name = strings.ToLower(updateRequest.NewName) } existing.UpdatedAt = nowMilli() @@ -113,14 +115,14 @@ func (s *FakeWorkspace) RegisteredModelsUpdate(req Request, fullName string) Res // moveRegisteredModel stores the model under the full name its catalog, schema and name now give it, // keeping its versions, as UC does when the model or its parent is renamed. func (s *FakeWorkspace) moveRegisteredModel(oldFullName string, model catalog.RegisteredModelInfo) catalog.RegisteredModelInfo { - delete(s.RegisteredModels, oldFullName) + delete(s.RegisteredModels, modelKey(oldFullName)) model.FullName = model.CatalogName + "." + model.SchemaName + "." + model.Name - s.RegisteredModels[model.FullName] = model + s.RegisteredModels[modelKey(model.FullName)] = model - versions, ok := s.RegisteredModelVersions[oldFullName] + versions, ok := s.RegisteredModelVersions[modelKey(oldFullName)] if ok { - delete(s.RegisteredModelVersions, oldFullName) - s.RegisteredModelVersions[model.FullName] = versions + delete(s.RegisteredModelVersions, modelKey(oldFullName)) + s.RegisteredModelVersions[modelKey(model.FullName)] = versions } return model } @@ -129,7 +131,7 @@ func (s *FakeWorkspace) moveRegisteredModel(oldFullName string, model catalog.Re func (s *FakeWorkspace) RegisteredModelsGet(req Request, fullName string) Response { defer s.LockUnlock()() - model, ok := s.RegisteredModels[fullName] + model, ok := s.RegisteredModels[modelKey(fullName)] if !ok { return registeredModelNotFound(fullName) } @@ -144,12 +146,12 @@ func (s *FakeWorkspace) RegisteredModelsGet(req Request, fullName string) Respon func (s *FakeWorkspace) RegisteredModelsDelete(fullName string) Response { defer s.LockUnlock()() - if _, ok := s.RegisteredModels[fullName]; !ok { + if _, ok := s.RegisteredModels[modelKey(fullName)]; !ok { return registeredModelNotFound(fullName) } - delete(s.RegisteredModels, fullName) + delete(s.RegisteredModels, modelKey(fullName)) // The model's versions are deleted with it, so a model created later under the same name starts with none. - delete(s.RegisteredModelVersions, fullName) + delete(s.RegisteredModelVersions, modelKey(fullName)) return Response{} } @@ -167,16 +169,16 @@ func (s *FakeWorkspace) RegisteredModelsCreateVersion(req Request) Response { StatusCode: http.StatusInternalServerError, } } - if _, ok := s.RegisteredModels[request.Name]; !ok { + if _, ok := s.RegisteredModels[modelKey(request.Name)]; !ok { return registeredModelNotFound(request.Name) } - s.RegisteredModelVersions[request.Name]++ + s.RegisteredModelVersions[modelKey(request.Name)]++ return Response{ Body: map[string]any{ "model_version": map[string]string{ "name": request.Name, - "version": strconv.Itoa(s.RegisteredModelVersions[request.Name]), + "version": strconv.Itoa(s.RegisteredModelVersions[modelKey(request.Name)]), }, }, } @@ -185,7 +187,7 @@ func (s *FakeWorkspace) RegisteredModelsCreateVersion(req Request) Response { func (s *FakeWorkspace) RegisteredModelsSetAlias(req Request, fullName, aliasName string) Response { defer s.LockUnlock()() - model, ok := s.RegisteredModels[fullName] + model, ok := s.RegisteredModels[modelKey(fullName)] if !ok { return registeredModelNotFound(fullName) } @@ -199,7 +201,7 @@ func (s *FakeWorkspace) RegisteredModelsSetAlias(req Request, fullName, aliasNam } // An alias can only point at a registered version. - if request.VersionNum < 1 || request.VersionNum > s.RegisteredModelVersions[fullName] { + if request.VersionNum < 1 || request.VersionNum > s.RegisteredModelVersions[modelKey(fullName)] { return Response{ StatusCode: http.StatusNotFound, Body: map[string]string{ @@ -226,7 +228,7 @@ func (s *FakeWorkspace) RegisteredModelsSetAlias(req Request, fullName, aliasNam aliases = append(aliases, alias) } model.Aliases = aliases - s.RegisteredModels[fullName] = model + s.RegisteredModels[modelKey(fullName)] = model return Response{ Body: alias, } @@ -235,7 +237,7 @@ func (s *FakeWorkspace) RegisteredModelsSetAlias(req Request, fullName, aliasNam func (s *FakeWorkspace) RegisteredModelsDeleteAlias(fullName, aliasName string) Response { defer s.LockUnlock()() - model, ok := s.RegisteredModels[fullName] + model, ok := s.RegisteredModels[modelKey(fullName)] if !ok { return registeredModelNotFound(fullName) } @@ -243,10 +245,16 @@ func (s *FakeWorkspace) RegisteredModelsDeleteAlias(fullName, aliasName string) model.Aliases = slices.DeleteFunc(slices.Clone(model.Aliases), func(a catalog.RegisteredModelAlias) bool { return a.AliasName == aliasName }) - s.RegisteredModels[fullName] = model + s.RegisteredModels[modelKey(fullName)] = model return Response{} } +// modelKey is the key a model is stored under. UC looks a full name up case-insensitively +// (checked on AWS: a model re-keyed as main.s.MyModel is still read at that path). +func modelKey(fullName string) string { + return strings.ToLower(fullName) +} + // registeredModelAlreadyExists is UC's answer to a create or rename onto a taken name; it names the // model by its short name (verified on AWS). func registeredModelAlreadyExists(name string) Response { diff --git a/libs/testserver/registered_models_test.go b/libs/testserver/registered_models_test.go index 835f90e0959..ec5e792f5b4 100644 --- a/libs/testserver/registered_models_test.go +++ b/libs/testserver/registered_models_test.go @@ -1,8 +1,11 @@ package testserver import ( + "net/url" "testing" + "github.com/databricks/databricks-sdk-go/service/catalog" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -42,3 +45,23 @@ func TestRegisteredModelsUpdate_RejectsRenameOntoExistingModel(t *testing.T) { assert.Contains(t, workspace.RegisteredModels, "main.default.model_a") assert.Contains(t, workspace.RegisteredModels, "main.default.model_b") } + +func TestRegisteredModels_NamesAreCaseInsensitive(t *testing.T) { + workspace := NewFakeWorkspace("http://test", "dbapi123") + require.Equal(t, 0, workspace.RegisteredModelsCreate(Request{Body: []byte(`{"catalog_name": "main", "schema_name": "default", "name": "MyModel"}`)}).StatusCode) + + // UC stores the name lowercased and finds the model under any casing. + response := workspace.RegisteredModelsGet(Request{URL: &url.URL{}}, "main.default.MYMODEL") + require.Equal(t, 0, response.StatusCode) + model, ok := response.Body.(catalog.RegisteredModelInfo) + require.True(t, ok) + assert.Equal(t, "mymodel", model.Name) + assert.Equal(t, "main.default.mymodel", model.FullName) + + // A rename that only changes the case keeps the lowercase name. + response = workspace.RegisteredModelsUpdate(Request{Body: []byte(`{"new_name": "MyModel"}`)}, "main.default.mymodel") + require.Equal(t, 0, response.StatusCode) + model, ok = response.Body.(catalog.RegisteredModelInfo) + require.True(t, ok) + assert.Equal(t, "mymodel", model.Name) +} From c25e83836bcaf12ba204e37d69116bc376907229 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Fri, 20 Nov 2026 13:56:14 +0100 Subject: [PATCH 41/44] acc: a case-only rename of a registered model keeps it as it was (review) Co-authored-by: Isaac --- .../rename_case_only/databricks.yml.tmpl | 13 ++ .../rename_case_only/out.test.toml | 2 + .../rename_case_only/output.txt | 155 ++++++++++++++++++ .../registered_models/rename_case_only/script | 34 ++++ .../rename_case_only/test.toml | 7 + 5 files changed, 211 insertions(+) create mode 100644 acceptance/bundle/resources/registered_models/rename_case_only/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/registered_models/rename_case_only/out.test.toml create mode 100644 acceptance/bundle/resources/registered_models/rename_case_only/output.txt create mode 100644 acceptance/bundle/resources/registered_models/rename_case_only/script create mode 100644 acceptance/bundle/resources/registered_models/rename_case_only/test.toml diff --git a/acceptance/bundle/resources/registered_models/rename_case_only/databricks.yml.tmpl b/acceptance/bundle/resources/registered_models/rename_case_only/databricks.yml.tmpl new file mode 100644 index 00000000000..b6c7cdd6cd9 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_case_only/databricks.yml.tmpl @@ -0,0 +1,13 @@ +bundle: + name: test-bundle-$UNIQUE_NAME + +resources: + schemas: + schema1: + catalog_name: main + name: test_schema_$UNIQUE_NAME + registered_models: + model1: + catalog_name: main + schema_name: ${resources.schemas.schema1.name} + name: mymodel diff --git a/acceptance/bundle/resources/registered_models/rename_case_only/out.test.toml b/acceptance/bundle/resources/registered_models/rename_case_only/out.test.toml new file mode 100644 index 00000000000..0f167effef1 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_case_only/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/registered_models/rename_case_only/output.txt b/acceptance/bundle/resources/registered_models/rename_case_only/output.txt new file mode 100644 index 00000000000..73fd7dfde02 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_case_only/output.txt @@ -0,0 +1,155 @@ + +=== Deploy a model with a lowercase name + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Created registered_models.model1 +Created schemas.schema1 +Files: 2 uploaded, 0 deleted +Resources: 2 created, 0 changed, 0 deleted, 0 unchanged + +=== Change only the case of the name. UC lowercases names, so the rename keeps the model as it was + +>>> update_file.py databricks.yml name: mymodel name: MyModel + +>>> [CLI] bundle plan --output json +{ + "resources.registered_models.model1": { + "depends_on": [ + { + "node": "resources.schemas.schema1", + "label": "${resources.schemas.schema1.name}" + } + ], + "action": "update_id", + "new_state": { + "value": { + "catalog_name": "main", + "name": "MyModel", + "schema_name": "test_schema_[UNIQUE_NAME]" + } + }, + "remote_state": { + "catalog_name": "main", + "created_by": "[USERNAME]", + "full_name": "main.test_schema_[UNIQUE_NAME].mymodel", + "name": "mymodel", + "owner": "[USERNAME]", + "schema_name": "test_schema_[UNIQUE_NAME]" + }, + "changes": { + "created_by": { + "action": "skip", + "reason": "output_only", + "remote": "[USERNAME]" + }, + "full_name": { + "action": "skip", + "reason": "backend_default", + "remote": "main.test_schema_[UNIQUE_NAME].mymodel" + }, + "name": { + "action": "update_id", + "reason": "id_changes", + "old": "mymodel", + "new": "MyModel", + "remote": "mymodel" + }, + "owner": { + "action": "skip", + "reason": "backend_default", + "remote": "[USERNAME]" + } + } + }, + "resources.schemas.schema1": { + "action": "skip", + "remote_state": { + "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": "[UUID]" + }, + "changes": { + "schema_id": { + "action": "skip", + "reason": "internal_id", + "old": "[UUID]", + "remote": "[UUID]" + } + } + } +} + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Updated registered_models.model1 +Files: 2 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 1 unchanged + +>>> print_requests.py //unity-catalog +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/models/main.test_schema_[UNIQUE_NAME].mymodel", + "body": { + "catalog_name": "main", + "comment": "", + "new_name": "MyModel", + "schema_name": "test_schema_[UNIQUE_NAME]" + } +} + +>>> [CLI] registered-models get main.test_schema_[UNIQUE_NAME].mymodel +{ + "full_name": "main.test_schema_[UNIQUE_NAME].mymodel", + "name": "mymodel", + "created_at": [MODEL_CREATED_AT] +} + +=== Redeploy + +>>> [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged + +=== Rename the schema. The model is re-keyed without a request. Its recorded ID keeps the config's casing, which UC reads case-insensitively + +>>> update_file.py databricks.yml test_schema_ test_schema_renamed_ + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Updated schemas.schema1 +Files: 1 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 1 unchanged + +>>> print_requests.py //unity-catalog +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/schemas/main.test_schema_[UNIQUE_NAME]", + "body": { + "comment": "", + "custom_max_retention_hours": 0, + "new_name": "test_schema_renamed_[UNIQUE_NAME]" + } +} + +>>> [CLI] bundle summary --output json +"main.test_schema_renamed_[UNIQUE_NAME].MyModel" + +>>> [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.registered_models.model1 + 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: 2 deleted diff --git a/acceptance/bundle/resources/registered_models/rename_case_only/script b/acceptance/bundle/resources/registered_models/rename_case_only/script new file mode 100644 index 00000000000..1b5946e048e --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_case_only/script @@ -0,0 +1,34 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +MODEL="main.test_schema_${UNIQUE_NAME}.mymodel" + +cleanup() { + trace $CLI bundle destroy --auto-approve + + # Consume the destroy's requests so none are left recorded. + print_requests.py //unity-catalog &> LOG.destroy_requests +} +trap cleanup EXIT + +title "Deploy a model with a lowercase name" +trace $CLI bundle deploy +print_requests.py //unity-catalog &> LOG.deploy_requests +add_repl "$($CLI registered-models get "$MODEL" | jq -r .created_at)" MODEL_CREATED_AT + +title "Change only the case of the name. UC lowercases names, so the rename keeps the model as it was" +trace update_file.py databricks.yml "name: mymodel" "name: MyModel" +# Drop the remote_state fields that differ between clouds or from the test server. +trace $CLI bundle plan --output json | jq .plan | normalize_uc_payload.py created_at updated_at updated_by metastore_id browse_only effective_predictive_optimization_flag storage_location +trace $CLI bundle deploy +trace print_requests.py //unity-catalog +trace $CLI registered-models get "$MODEL" | jq '{full_name, name, created_at}' + +title "Redeploy" +trace $CLI bundle plan + +title "Rename the schema. The model is re-keyed without a request. Its recorded ID keeps the config's casing, which UC reads case-insensitively" +trace update_file.py databricks.yml test_schema_ test_schema_renamed_ +trace $CLI bundle deploy +trace print_requests.py //unity-catalog +trace $CLI bundle summary --output json | jq '.resources.registered_models.model1.id' +trace $CLI bundle plan diff --git a/acceptance/bundle/resources/registered_models/rename_case_only/test.toml b/acceptance/bundle/resources/registered_models/rename_case_only/test.toml new file mode 100644 index 00000000000..4272a80cf61 --- /dev/null +++ b/acceptance/bundle/resources/registered_models/rename_case_only/test.toml @@ -0,0 +1,7 @@ +Cloud = true + +Ignore = [ + ".databricks", + ".gitignore", + "databricks.yml", +] From c90244678d58d5833f8893d250983489a72ea932 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Fri, 20 Nov 2026 13:56:15 +0100 Subject: [PATCH 42/44] acc: rename a model's schema and change the model in one deploy, on cloud (review) Co-authored-by: Isaac --- .../registered_models/rename/output.txt | 45 ++++++++++++++++++- .../resources/registered_models/rename/script | 7 +++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/acceptance/bundle/resources/registered_models/rename/output.txt b/acceptance/bundle/resources/registered_models/rename/output.txt index d26ba832ca5..0e8837b15d4 100644 --- a/acceptance/bundle/resources/registered_models/rename/output.txt +++ b/acceptance/bundle/resources/registered_models/rename/output.txt @@ -162,15 +162,56 @@ Resources: 0 created, 1 changed, 0 deleted, 1 unchanged "created_at": [MODEL_CREATED_AT] } +=== Rename the schema and change the model's comment in one deploy. UC moves the model with the schema: its new path is recorded first, then one PATCH sets the comment there + +>>> update_file.py databricks.yml test-schema- test-schema-renamed- + +>>> update_file.py databricks.yml comment: c2 comment: c3 + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... +Updated registered_models.model1 +Updated schemas.schema1 +Files: 1 uploaded, 0 deleted +Resources: 0 created, 2 changed, 0 deleted, 0 unchanged + +>>> print_requests.py //unity-catalog +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/schemas/main.test-schema-[UNIQUE_NAME]", + "body": { + "comment": "", + "custom_max_retention_hours": 0, + "new_name": "test-schema-renamed-[UNIQUE_NAME]" + } +} +{ + "method": "PATCH", + "path": "/api/2.1/unity-catalog/models/main.test-schema-renamed-[UNIQUE_NAME].mymodel3", + "body": { + "catalog_name": "main", + "comment": "c3", + "name": "mymodel3", + "schema_name": "test-schema-renamed-[UNIQUE_NAME]" + } +} + +>>> [CLI] registered-models get main.test-schema-renamed-[UNIQUE_NAME].mymodel3 +{ + "full_name": "main.test-schema-renamed-[UNIQUE_NAME].mymodel3", + "comment": "c3", + "created_at": [MODEL_CREATED_AT] +} + === The state tracks the new name and the plan is a no-op >>> [CLI] bundle summary --output json { "registered_models": { - "model1": "main.test-schema-[UNIQUE_NAME].mymodel3" + "model1": "main.test-schema-renamed-[UNIQUE_NAME].mymodel3" }, "schemas": { - "schema1": "main.test-schema-[UNIQUE_NAME]" + "schema1": "main.test-schema-renamed-[UNIQUE_NAME]" } } diff --git a/acceptance/bundle/resources/registered_models/rename/script b/acceptance/bundle/resources/registered_models/rename/script index 4945c5ccd92..abbdaf25774 100644 --- a/acceptance/bundle/resources/registered_models/rename/script +++ b/acceptance/bundle/resources/registered_models/rename/script @@ -30,6 +30,13 @@ trace $CLI bundle deploy trace print_requests.py //unity-catalog trace $CLI registered-models get "$SCHEMA.mymodel3" | jq '{full_name, comment, created_at}' +title "Rename the schema and change the model's comment in one deploy. UC moves the model with the schema: its new path is recorded first, then one PATCH sets the comment there" +trace update_file.py databricks.yml test-schema- test-schema-renamed- +trace update_file.py databricks.yml "comment: c2" "comment: c3" +trace $CLI bundle deploy +trace print_requests.py //unity-catalog +trace $CLI registered-models get "main.test-schema-renamed-${UNIQUE_NAME}.mymodel3" | jq '{full_name, comment, created_at}' + title "The state tracks the new name and the plan is a no-op" trace $CLI bundle summary --output json | jq '.resources | map_values(map_values(.id))' trace $CLI bundle plan From 0fe3522d33653d374d3cc910bfaf9b7e46ded01c Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Fri, 20 Nov 2026 13:56:16 +0100 Subject: [PATCH 43/44] acc: the model out-of-band deploy must fail, so use musterr (review) Co-authored-by: Isaac --- .../registered_models/parent_rename_out_of_band/output.txt | 4 +--- .../registered_models/parent_rename_out_of_band/script | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/output.txt b/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/output.txt index 7412e7de1a0..dd0f0fb6294 100644 --- a/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/output.txt +++ b/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/output.txt @@ -26,7 +26,7 @@ Plan: 1 to add, 0 to change, 0 to delete, 1 unchanged === The create fails: the model is already there ->>> errcode [CLI] bundle deploy +>>> musterr [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files... Error: cannot create resources.registered_models.model1: Routine or Model 'mymodel' already exists (400 RESOURCE_ALREADY_EXISTS) @@ -37,8 +37,6 @@ API message: Routine or Model 'mymodel' already exists Files: 3 uploaded, 0 deleted -Exit code: 1 - >>> print_requests.py //unity-catalog { "method": "POST", diff --git a/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/script b/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/script index bbd254c0797..23be1d40e08 100644 --- a/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/script +++ b/acceptance/bundle/resources/registered_models/parent_rename_out_of_band/script @@ -24,6 +24,6 @@ trace update_file.py databricks.yml test-schema- test-schema-renamed- trace $CLI bundle plan title "The create fails: the model is already there" -trace errcode $CLI bundle deploy +trace musterr $CLI bundle deploy trace print_requests.py //unity-catalog trace $CLI registered-models get "$NEW_SCHEMA.mymodel" | jq '{full_name}' From 72adf9c1b7e7cafdc0cd8c40cefb65a08a01eba6 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Fri, 20 Nov 2026 13:56:17 +0100 Subject: [PATCH 44/44] Describe what users see in the changelog entry and PR title (review) Co-authored-by: Isaac --- .nextchanges/bundles/registered-model-rename.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/bundles/registered-model-rename.md b/.nextchanges/bundles/registered-model-rename.md index 8b45402ed03..5d4b2d30243 100644 --- a/.nextchanges/bundles/registered-model-rename.md +++ b/.nextchanges/bundles/registered-model-rename.md @@ -1 +1 @@ -* Rename registered models in place and follow parent renames. ([#7379](https://github.com/databricks/cli/pull/7379)) +* Rename registered models in place; a model in a renamed catalog or schema keeps its versions. ([#7379](https://github.com/databricks/cli/pull/7379))