Skip to content

Commit b0476cd

Browse files
denikIsaac
andcommitted
direct: let the framework re-key a model that only follows its parent; test rename with a comment change
Co-authored-by: Isaac <no-reply@databricks.com>
1 parent f0cec60 commit b0476cd

4 files changed

Lines changed: 57 additions & 24 deletions

File tree

‎acceptance/bundle/resources/registered_models/rename/databricks.yml.tmpl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ resources:
1414
catalog_name: ${resources.catalogs.catalog1.name}
1515
schema_name: ${resources.schemas.schema1.name}
1616
name: mymodel
17+
comment: c1

‎acceptance/bundle/resources/registered_models/rename/output.txt‎

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged
2929
"path": "/api/2.1/unity-catalog/models",
3030
"body": {
3131
"catalog_name": "test_catalog_[UNIQUE_NAME]",
32+
"comment": "c1",
3233
"name": "mymodel",
3334
"schema_name": "myschema"
3435
}
@@ -64,12 +65,14 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged
6465
"new_state": {
6566
"value": {
6667
"catalog_name": "test_catalog_[UNIQUE_NAME]",
68+
"comment": "c1",
6769
"name": "mymodel2",
6870
"schema_name": "myschema"
6971
}
7072
},
7173
"remote_state": {
7274
"catalog_name": "test_catalog_[UNIQUE_NAME]",
75+
"comment": "c1",
7376
"created_by": "[USERNAME]",
7477
"full_name": "test_catalog_[UNIQUE_NAME].myschema.mymodel",
7578
"name": "mymodel",
@@ -141,7 +144,7 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged
141144
"path": "/api/2.1/unity-catalog/models/test_catalog_[UNIQUE_NAME].myschema.mymodel",
142145
"body": {
143146
"catalog_name": "test_catalog_[UNIQUE_NAME]",
144-
"comment": "",
147+
"comment": "c1",
145148
"new_name": "mymodel2",
146149
"schema_name": "myschema"
147150
}
@@ -180,28 +183,25 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged
180183
}
181184
],
182185
"action": "update_id",
186+
"state_only": true,
183187
"new_state": {
184188
"value": {
185189
"catalog_name": "test_catalog_[UNIQUE_NAME]",
190+
"comment": "c1",
186191
"name": "mymodel2",
187192
"schema_name": "myschema2"
188193
}
189194
},
190195
"remote_state": {
191196
"catalog_name": "test_catalog_[UNIQUE_NAME]",
192-
"comment": "",
197+
"comment": "c1",
193198
"created_by": "[USERNAME]",
194199
"full_name": "test_catalog_[UNIQUE_NAME].myschema.mymodel2",
195200
"name": "mymodel2",
196201
"owner": "[USERNAME]",
197202
"schema_name": "myschema"
198203
},
199204
"changes": {
200-
"comment": {
201-
"action": "skip",
202-
"reason": "empty",
203-
"remote": ""
204-
},
205205
"created_by": {
206206
"action": "skip",
207207
"reason": "output_only",
@@ -269,10 +269,9 @@ Resources: 0 created, 1 changed, 0 deleted, 2 unchanged
269269

270270
>>> [CLI] bundle deploy
271271
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files...
272-
Updated registered_models.model1
273272
Updated schemas.schema1
274273
Files: 1 uploaded, 0 deleted
275-
Resources: 0 created, 2 changed, 0 deleted, 1 unchanged
274+
Resources: 0 created, 1 changed, 0 deleted, 2 unchanged
276275

277276
>>> print_requests.py //unity-catalog
278277
{
@@ -332,16 +331,18 @@ Resources: 0 created, 2 changed, 0 deleted, 1 unchanged
332331
}
333332
],
334333
"action": "update_id",
334+
"state_only": true,
335335
"new_state": {
336336
"value": {
337337
"catalog_name": "test_catalog_renamed_[UNIQUE_NAME]",
338+
"comment": "c1",
338339
"name": "mymodel2",
339340
"schema_name": "myschema2"
340341
}
341342
},
342343
"remote_state": {
343344
"catalog_name": "test_catalog_[UNIQUE_NAME]",
344-
"comment": "",
345+
"comment": "c1",
345346
"created_by": "[USERNAME]",
346347
"full_name": "test_catalog_[UNIQUE_NAME].myschema2.mymodel2",
347348
"name": "mymodel2",
@@ -356,11 +357,6 @@ Resources: 0 created, 2 changed, 0 deleted, 1 unchanged
356357
"new": "test_catalog_renamed_[UNIQUE_NAME]",
357358
"remote": "test_catalog_[UNIQUE_NAME]"
358359
},
359-
"comment": {
360-
"action": "skip",
361-
"reason": "empty",
362-
"remote": ""
363-
},
364360
"created_by": {
365361
"action": "skip",
366362
"reason": "output_only",
@@ -386,6 +382,7 @@ Resources: 0 created, 2 changed, 0 deleted, 1 unchanged
386382
}
387383
],
388384
"action": "update_id",
385+
"state_only": true,
389386
"new_state": {
390387
"value": {
391388
"catalog_name": "test_catalog_renamed_[UNIQUE_NAME]",
@@ -434,10 +431,8 @@ Resources: 0 created, 2 changed, 0 deleted, 1 unchanged
434431
>>> [CLI] bundle deploy
435432
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files...
436433
Updated catalogs.catalog1
437-
Updated registered_models.model1
438-
Updated schemas.schema1
439434
Files: 1 uploaded, 0 deleted
440-
Resources: 0 created, 3 changed, 0 deleted, 0 unchanged
435+
Resources: 0 created, 1 changed, 0 deleted, 2 unchanged
441436

442437
>>> print_requests.py //unity-catalog
443438
{
@@ -456,14 +451,44 @@ Resources: 0 created, 3 changed, 0 deleted, 0 unchanged
456451
"created_at": [MODEL_CREATED_AT]
457452
}
458453

454+
=== Rename the model and change its comment in one deploy: both go in one PATCH
455+
>>> update_file.py databricks.yml name: mymodel2 name: mymodel3
456+
457+
>>> update_file.py databricks.yml comment: c1 comment: c2
458+
459+
>>> [CLI] bundle deploy
460+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default/files...
461+
Updated registered_models.model1
462+
Files: 1 uploaded, 0 deleted
463+
Resources: 0 created, 1 changed, 0 deleted, 2 unchanged
464+
465+
>>> print_requests.py //unity-catalog
466+
{
467+
"method": "PATCH",
468+
"path": "/api/2.1/unity-catalog/models/test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel2",
469+
"body": {
470+
"catalog_name": "test_catalog_renamed_[UNIQUE_NAME]",
471+
"comment": "c2",
472+
"new_name": "mymodel3",
473+
"schema_name": "myschema2"
474+
}
475+
}
476+
477+
>>> [CLI] registered-models get test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel3
478+
{
479+
"full_name": "test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel3",
480+
"comment": "c2",
481+
"created_at": [MODEL_CREATED_AT]
482+
}
483+
459484
=== The state tracks the new paths and the plan is a no-op
460485
>>> [CLI] bundle summary --output json
461486
{
462487
"catalogs": {
463488
"catalog1": "test_catalog_renamed_[UNIQUE_NAME]"
464489
},
465490
"registered_models": {
466-
"model1": "test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel2"
491+
"model1": "test_catalog_renamed_[UNIQUE_NAME].myschema2.mymodel3"
467492
},
468493
"schemas": {
469494
"schema1": "test_catalog_renamed_[UNIQUE_NAME].myschema2"

‎acceptance/bundle/resources/registered_models/rename/script‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ trace $CLI bundle deploy
3939
trace print_requests.py //unity-catalog
4040
trace $CLI registered-models get "test_catalog_renamed_${UNIQUE_NAME}.myschema2.mymodel2" | jq '{full_name, created_at}'
4141

42+
title "Rename the model and change its comment in one deploy: both go in one PATCH"
43+
trace update_file.py databricks.yml "name: mymodel2" "name: mymodel3"
44+
trace update_file.py databricks.yml "comment: c1" "comment: c2"
45+
trace $CLI bundle deploy
46+
trace print_requests.py //unity-catalog
47+
trace $CLI registered-models get "test_catalog_renamed_${UNIQUE_NAME}.myschema2.mymodel3" | jq '{full_name, comment, created_at}'
48+
4249
title "The state tracks the new paths and the plan is a no-op"
4350
trace $CLI bundle summary --output json | jq '.resources | map_values(map_values(.id))'
4451
trace $CLI bundle plan

‎bundle/direct/dresources/registered_model.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,6 @@ func (r *ResourceRegisteredModel) DoUpdateWithID(ctx context.Context, id string,
147147
parent := config.CatalogName + "." + config.SchemaName + "."
148148
newID := parent + config.Name
149149

150-
if entry.Changes.OnlyParentRenamed() {
151-
// UC already moved the model with its parent; only the ID changes.
152-
return newID, nil, nil
153-
}
154-
155150
newName := ""
156151
if config.Name != nameFromID {
157152
newName = config.Name
@@ -228,6 +223,11 @@ func (*ResourceRegisteredModel) OverrideChangeDesc(_ context.Context, path *stru
228223
return nil
229224
}
230225

226+
// IDFromState returns the full name, which is the ID.
227+
func (*ResourceRegisteredModel) IDFromState(state *catalog.CreateRegisteredModelRequest) string {
228+
return state.CatalogName + "." + state.SchemaName + "." + state.Name
229+
}
230+
231231
func (r *ResourceRegisteredModel) DoDelete(ctx context.Context, id string, _ *catalog.CreateRegisteredModelRequest) error {
232232
return r.client.RegisteredModels.Delete(ctx, catalog.DeleteRegisteredModelRequest{
233233
FullName: id,

0 commit comments

Comments
 (0)