From 6692d77a3f251a4c32024aa3007d41a5ebf1e6a3 Mon Sep 17 00:00:00 2001 From: Factory Local Trial Date: Mon, 2 Nov 2026 08:32:17 +0000 Subject: [PATCH 1/5] [factory] Fix qualified DABs behavior --- .../mutator/resourcemutator/apply_presets.go | 23 ++++++++- .../resourcemutator/apply_presets_test.go | 51 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/bundle/config/mutator/resourcemutator/apply_presets.go b/bundle/config/mutator/resourcemutator/apply_presets.go index bb84240d7cc..e464c8fcce3 100644 --- a/bundle/config/mutator/resourcemutator/apply_presets.go +++ b/bundle/config/mutator/resourcemutator/apply_presets.go @@ -208,7 +208,7 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos if s == nil { continue } - s.Name = normalizePrefix(prefix) + s.Name + s.Name = normalizeSchemaPrefix(prefix, b) + s.Name // HTTP API for schemas doesn't yet support tags. It's only supported in // the Databricks UI and via the SQL API. } @@ -387,3 +387,24 @@ func normalizePrefix(prefix string) string { return textutil.NormalizeString(prefix) + suffix } + +func normalizeSchemaPrefix(prefix string, b *bundle.Bundle) string { + user := b.Config.Workspace.CurrentUser + // Preserve the existing normalization for prefixes generated by development mode. + if b.Config.Bundle.Mode == config.Development && user != nil && prefix == "[dev "+user.ShortName+"] " { + return normalizePrefix(prefix) + } + + prefix = strings.ReplaceAll(prefix, "[", "") + prefix = strings.Trim(prefix, " ") + suffix := "" + if strings.HasSuffix(prefix, "]") { + suffix = "_" + } + + parts := strings.Split(prefix, "_") + for i := range parts { + parts[i] = textutil.NormalizeString(parts[i]) + } + return strings.Join(parts, "_") + suffix +} diff --git a/bundle/config/mutator/resourcemutator/apply_presets_test.go b/bundle/config/mutator/resourcemutator/apply_presets_test.go index c97db137b26..9a18cbdd9f4 100644 --- a/bundle/config/mutator/resourcemutator/apply_presets_test.go +++ b/bundle/config/mutator/resourcemutator/apply_presets_test.go @@ -38,3 +38,54 @@ func TestApplyPresetsSkipsNilQualityMonitors(t *testing.T) { require.NoError(t, diags.Error()) assert.Nil(t, b.Config.Resources.QualityMonitors["monitor"].Schedule) } + +func TestApplyPresetsSchemaPrefixPreservesUnderscores(t *testing.T) { + tests := []struct { + name string + prefix string + expected string + }{ + {"trailing underscore", "my_user_", "my_user_qc"}, + {"repeated underscores", "my__user__", "my__user__qc"}, + {"bracketed underscores", "[qa__team] ", "qa__team_qc"}, + {"bracketed prefix", "[prod] ", "prod_qc"}, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + b := &bundle.Bundle{ + Config: config.Root{ + Presets: config.Presets{NamePrefix: test.prefix}, + Resources: config.Resources{ + Schemas: map[string]*resources.Schema{ + "qc": {CreateSchema: catalog.CreateSchema{CatalogName: "my_catalog", Name: "qc"}}, + }, + }, + }, + } + + diags := bundle.Apply(t.Context(), b, ApplyPresets()) + require.NoError(t, diags.Error()) + assert.Equal(t, test.expected, b.Config.Resources.Schemas["qc"].Name) + }) + } + + b := &bundle.Bundle{ + Config: config.Root{ + Bundle: config.Bundle{Mode: config.Development}, + Presets: config.Presets{Tags: map[string]string{"dev": "my__user"}}, + Workspace: config.Workspace{ + CurrentUser: &config.User{ShortName: "my__user"}, + }, + Resources: config.Resources{ + Schemas: map[string]*resources.Schema{ + "qc": {CreateSchema: catalog.CreateSchema{CatalogName: "my_catalog", Name: "qc"}}, + }, + }, + }, + } + + diags := bundle.ApplySeq(t.Context(), b, ApplyTargetMode(), ApplyPresets()) + require.NoError(t, diags.Error()) + assert.Equal(t, "dev_my_user_qc", b.Config.Resources.Schemas["qc"].Name) +} From f04aa2d0b40878fb5cfb23402075395ee4646292 Mon Sep 17 00:00:00 2001 From: Factory Local Trial Date: Mon, 2 Nov 2026 19:03:17 +0000 Subject: [PATCH 2/5] [factory] Repair attached DABs CI --- bundle/config/mutator/resourcemutator/apply_presets_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/config/mutator/resourcemutator/apply_presets_test.go b/bundle/config/mutator/resourcemutator/apply_presets_test.go index 9a18cbdd9f4..cfa3df95c5a 100644 --- a/bundle/config/mutator/resourcemutator/apply_presets_test.go +++ b/bundle/config/mutator/resourcemutator/apply_presets_test.go @@ -72,7 +72,7 @@ func TestApplyPresetsSchemaPrefixPreservesUnderscores(t *testing.T) { b := &bundle.Bundle{ Config: config.Root{ - Bundle: config.Bundle{Mode: config.Development}, + Bundle: config.Bundle{Mode: config.Development}, Presets: config.Presets{Tags: map[string]string{"dev": "my__user"}}, Workspace: config.Workspace{ CurrentUser: &config.User{ShortName: "my__user"}, From 507953d09b867439fcb9c9cd111b2d86e580a40f Mon Sep 17 00:00:00 2001 From: Lennart Kats Date: Fri, 13 Nov 2026 10:42:28 +0000 Subject: [PATCH 3/5] Preserve underscores in normalized bundle preset names --- .../name_prefix_underscores/databricks.yml | 25 ++++++++++ .../name_prefix_underscores/out.test.toml | 2 + .../name_prefix_underscores/output.txt | 21 ++++++++ .../presets/name_prefix_underscores/script | 3 ++ .../mutator/resourcemutator/apply_presets.go | 35 +++---------- .../resourcemutator/apply_presets_test.go | 49 ++++++++----------- 6 files changed, 80 insertions(+), 55 deletions(-) create mode 100644 acceptance/bundle/presets/name_prefix_underscores/databricks.yml create mode 100644 acceptance/bundle/presets/name_prefix_underscores/out.test.toml create mode 100644 acceptance/bundle/presets/name_prefix_underscores/output.txt create mode 100644 acceptance/bundle/presets/name_prefix_underscores/script diff --git a/acceptance/bundle/presets/name_prefix_underscores/databricks.yml b/acceptance/bundle/presets/name_prefix_underscores/databricks.yml new file mode 100644 index 00000000000..933a4077a69 --- /dev/null +++ b/acceptance/bundle/presets/name_prefix_underscores/databricks.yml @@ -0,0 +1,25 @@ +bundle: + name: name_prefix_underscores + +resources: + schemas: + qc: + name: qc + catalog_name: my_catalog + registered_models: + model: + name: model + model_serving_endpoints: + endpoint: + name: endpoint + +targets: + trailing: + default: true + presets: + name_prefix: ${workspace.current_user.short_name}_ + repeated: + presets: + name_prefix: team__${workspace.current_user.short_name}__ + generated: + mode: development diff --git a/acceptance/bundle/presets/name_prefix_underscores/out.test.toml b/acceptance/bundle/presets/name_prefix_underscores/out.test.toml new file mode 100644 index 00000000000..a927a5fbc06 --- /dev/null +++ b/acceptance/bundle/presets/name_prefix_underscores/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/presets/name_prefix_underscores/output.txt b/acceptance/bundle/presets/name_prefix_underscores/output.txt new file mode 100644 index 00000000000..6f96c626e97 --- /dev/null +++ b/acceptance/bundle/presets/name_prefix_underscores/output.txt @@ -0,0 +1,21 @@ + +>>> [CLI] bundle validate -o json -t trailing +{ + "schema": "[USERNAME]_qc", + "model": "[USERNAME]_model", + "endpoint": "[USERNAME]_endpoint" +} + +>>> [CLI] bundle validate -o json -t repeated +{ + "schema": "team__[USERNAME]__qc", + "model": "team__[USERNAME]__model", + "endpoint": "team__[USERNAME]__endpoint" +} + +>>> [CLI] bundle validate -o json -t generated +{ + "schema": "dev_[USERNAME]_qc", + "model": "dev_[USERNAME]_model", + "endpoint": "dev_[USERNAME]_endpoint" +} diff --git a/acceptance/bundle/presets/name_prefix_underscores/script b/acceptance/bundle/presets/name_prefix_underscores/script new file mode 100644 index 00000000000..4d20aece393 --- /dev/null +++ b/acceptance/bundle/presets/name_prefix_underscores/script @@ -0,0 +1,3 @@ +trace $CLI bundle validate -o json -t trailing | jq '{schema: .resources.schemas.qc.name, model: .resources.registered_models.model.name, endpoint: .resources.model_serving_endpoints.endpoint.name}' +trace $CLI bundle validate -o json -t repeated | jq '{schema: .resources.schemas.qc.name, model: .resources.registered_models.model.name, endpoint: .resources.model_serving_endpoints.endpoint.name}' +trace $CLI bundle validate -o json -t generated | jq '{schema: .resources.schemas.qc.name, model: .resources.registered_models.model.name, endpoint: .resources.model_serving_endpoints.endpoint.name}' diff --git a/bundle/config/mutator/resourcemutator/apply_presets.go b/bundle/config/mutator/resourcemutator/apply_presets.go index e464c8fcce3..f7c9ac36978 100644 --- a/bundle/config/mutator/resourcemutator/apply_presets.go +++ b/bundle/config/mutator/resourcemutator/apply_presets.go @@ -208,7 +208,7 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos if s == nil { continue } - s.Name = normalizeSchemaPrefix(prefix, b) + s.Name + s.Name = normalizePrefix(prefix) + s.Name // HTTP API for schemas doesn't yet support tags. It's only supported in // the Databricks UI and via the SQL API. } @@ -372,39 +372,20 @@ func toTagArray(tags map[string]string) []Tag { return tagArray } -// normalizePrefix prefixes strings like '[dev lennart] ' to 'dev_lennart_'. -// We leave unicode letters and numbers but remove all "special characters." +// normalizePrefix normalizes special characters while preserving explicit underscores. func normalizePrefix(prefix string) string { prefix = strings.ReplaceAll(prefix, "[", "") prefix = strings.Trim(prefix, " ") - // If the prefix ends with a ']', we add an underscore to the end. - // This makes sure that we get names like "dev_user_endpoint" instead of "dev_userendpoint" - suffix := "" - if strings.HasSuffix(prefix, "]") { - suffix = "_" - } - - return textutil.NormalizeString(prefix) + suffix -} - -func normalizeSchemaPrefix(prefix string, b *bundle.Bundle) string { - user := b.Config.Workspace.CurrentUser - // Preserve the existing normalization for prefixes generated by development mode. - if b.Config.Bundle.Mode == config.Development && user != nil && prefix == "[dev "+user.ShortName+"] " { - return normalizePrefix(prefix) - } - - prefix = strings.ReplaceAll(prefix, "[", "") - prefix = strings.Trim(prefix, " ") - suffix := "" - if strings.HasSuffix(prefix, "]") { - suffix = "_" - } + bracketed := strings.HasSuffix(prefix, "]") parts := strings.Split(prefix, "_") for i := range parts { parts[i] = textutil.NormalizeString(parts[i]) } - return strings.Join(parts, "_") + suffix + normalized := strings.Join(parts, "_") + if bracketed && !strings.HasSuffix(normalized, "_") { + normalized += "_" + } + return normalized } diff --git a/bundle/config/mutator/resourcemutator/apply_presets_test.go b/bundle/config/mutator/resourcemutator/apply_presets_test.go index cfa3df95c5a..3e01495914e 100644 --- a/bundle/config/mutator/resourcemutator/apply_presets_test.go +++ b/bundle/config/mutator/resourcemutator/apply_presets_test.go @@ -7,6 +7,7 @@ import ( "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/bundle/config/resources" "github.com/databricks/databricks-sdk-go/service/catalog" + "github.com/databricks/databricks-sdk-go/service/serving" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -39,16 +40,19 @@ func TestApplyPresetsSkipsNilQualityMonitors(t *testing.T) { assert.Nil(t, b.Config.Resources.QualityMonitors["monitor"].Schedule) } -func TestApplyPresetsSchemaPrefixPreservesUnderscores(t *testing.T) { +func TestApplyPresetsNormalizedPrefixPreservesUnderscores(t *testing.T) { tests := []struct { - name string - prefix string - expected string + name string + prefix string + wantPrefix string }{ - {"trailing underscore", "my_user_", "my_user_qc"}, - {"repeated underscores", "my__user__", "my__user__qc"}, - {"bracketed underscores", "[qa__team] ", "qa__team_qc"}, - {"bracketed prefix", "[prod] ", "prod_qc"}, + {"trailing underscore", "my_user_", "my_user_"}, + {"repeated underscores", "my__user__", "my__user__"}, + {"bracketed underscores", "[qa__team] ", "qa__team_"}, + {"bracketed trailing underscore", "[qa_] ", "qa_"}, + {"bracketed repeated trailing underscores", "[qa__] ", "qa__"}, + {"bracketed prefix", "[prod] ", "prod_"}, + {"other separators", "a-b", "a_b"}, } for _, test := range tests { @@ -60,32 +64,21 @@ func TestApplyPresetsSchemaPrefixPreservesUnderscores(t *testing.T) { Schemas: map[string]*resources.Schema{ "qc": {CreateSchema: catalog.CreateSchema{CatalogName: "my_catalog", Name: "qc"}}, }, + RegisteredModels: map[string]*resources.RegisteredModel{ + "model": {CreateRegisteredModelRequest: catalog.CreateRegisteredModelRequest{Name: "model"}}, + }, + ModelServingEndpoints: map[string]*resources.ModelServingEndpoint{ + "endpoint": {CreateServingEndpoint: serving.CreateServingEndpoint{Name: "endpoint"}}, + }, }, }, } diags := bundle.Apply(t.Context(), b, ApplyPresets()) require.NoError(t, diags.Error()) - assert.Equal(t, test.expected, b.Config.Resources.Schemas["qc"].Name) + assert.Equal(t, test.wantPrefix+"qc", b.Config.Resources.Schemas["qc"].Name) + assert.Equal(t, test.wantPrefix+"model", b.Config.Resources.RegisteredModels["model"].Name) + assert.Equal(t, test.wantPrefix+"endpoint", b.Config.Resources.ModelServingEndpoints["endpoint"].Name) }) } - - b := &bundle.Bundle{ - Config: config.Root{ - Bundle: config.Bundle{Mode: config.Development}, - Presets: config.Presets{Tags: map[string]string{"dev": "my__user"}}, - Workspace: config.Workspace{ - CurrentUser: &config.User{ShortName: "my__user"}, - }, - Resources: config.Resources{ - Schemas: map[string]*resources.Schema{ - "qc": {CreateSchema: catalog.CreateSchema{CatalogName: "my_catalog", Name: "qc"}}, - }, - }, - }, - } - - diags := bundle.ApplySeq(t.Context(), b, ApplyTargetMode(), ApplyPresets()) - require.NoError(t, diags.Error()) - assert.Equal(t, "dev_my_user_qc", b.Config.Resources.Schemas["qc"].Name) } From 83c05ec23ec2cd5649043659e13371e8b0d271d1 Mon Sep 17 00:00:00 2001 From: Lennart Kats Date: Fri, 13 Nov 2026 14:28:05 +0000 Subject: [PATCH 4/5] Document schema prefix migration risk --- .../bundles/name-prefix-underscores.md | 1 + .../databricks.yml | 14 +++++++++++++ .../name_prefix_existing_schema/out.test.toml | 2 ++ .../name_prefix_existing_schema/output.txt | 20 +++++++++++++++++++ .../name_prefix_existing_schema/script | 8 ++++++++ 5 files changed, 45 insertions(+) create mode 100644 .nextchanges/bundles/name-prefix-underscores.md create mode 100644 acceptance/bundle/presets/name_prefix_existing_schema/databricks.yml create mode 100644 acceptance/bundle/presets/name_prefix_existing_schema/out.test.toml create mode 100644 acceptance/bundle/presets/name_prefix_existing_schema/output.txt create mode 100644 acceptance/bundle/presets/name_prefix_existing_schema/script diff --git a/.nextchanges/bundles/name-prefix-underscores.md b/.nextchanges/bundles/name-prefix-underscores.md new file mode 100644 index 00000000000..20efbcd7a23 --- /dev/null +++ b/.nextchanges/bundles/name-prefix-underscores.md @@ -0,0 +1 @@ +* Fix underscores in custom `presets.name_prefix` for schemas, registered models, and serving endpoints; existing deployments using such prefixes may recreate these resources, and schema recreation can delete data, so inspect `bundle plan` before deploying. ([#7287](https://github.com/databricks/cli/pull/7287)) diff --git a/acceptance/bundle/presets/name_prefix_existing_schema/databricks.yml b/acceptance/bundle/presets/name_prefix_existing_schema/databricks.yml new file mode 100644 index 00000000000..eeeca9fa637 --- /dev/null +++ b/acceptance/bundle/presets/name_prefix_existing_schema/databricks.yml @@ -0,0 +1,14 @@ +bundle: + name: name-prefix-existing-schema + +resources: + schemas: + qc: + name: qc + catalog_name: main + +targets: + existing: + default: true + presets: + name_prefix: my_user diff --git a/acceptance/bundle/presets/name_prefix_existing_schema/out.test.toml b/acceptance/bundle/presets/name_prefix_existing_schema/out.test.toml new file mode 100644 index 00000000000..a927a5fbc06 --- /dev/null +++ b/acceptance/bundle/presets/name_prefix_existing_schema/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/presets/name_prefix_existing_schema/output.txt b/acceptance/bundle/presets/name_prefix_existing_schema/output.txt new file mode 100644 index 00000000000..bb826458bc6 --- /dev/null +++ b/acceptance/bundle/presets/name_prefix_existing_schema/output.txt @@ -0,0 +1,20 @@ + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/name-prefix-existing-schema/existing/files... +Created schemas.qc +Files: 1 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +>>> [CLI] bundle summary -o json +"main.my_userqc" + +>>> [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged + +=== A corrected prefix plans to recreate the existing schema +>>> update_file.py databricks.yml name_prefix: my_user name_prefix: my_user_ + +>>> [CLI] bundle plan +recreate schemas.qc + +Plan: 1 to add, 0 to change, 1 to delete, 0 unchanged diff --git a/acceptance/bundle/presets/name_prefix_existing_schema/script b/acceptance/bundle/presets/name_prefix_existing_schema/script new file mode 100644 index 00000000000..c41534842ca --- /dev/null +++ b/acceptance/bundle/presets/name_prefix_existing_schema/script @@ -0,0 +1,8 @@ +# Older CLIs resolve my_user_ to my_userqc, the name created here. +trace $CLI bundle deploy +trace $CLI bundle summary -o json | jq .resources.schemas.qc.id +trace $CLI bundle plan + +title "A corrected prefix plans to recreate the existing schema" +trace update_file.py databricks.yml "name_prefix: my_user" "name_prefix: my_user_" +trace $CLI bundle plan From d8674d9c7b025370bc4f8d63f096f682cae1496e Mon Sep 17 00:00:00 2001 From: Lennart Kats Date: Fri, 13 Nov 2026 15:06:46 +0000 Subject: [PATCH 5/5] Align prefix migration evidence with schema rename --- .../bundles/name-prefix-underscores.md | 2 +- .../name_prefix_existing_schema/output.txt | 22 ++++++++++++++++--- .../name_prefix_existing_schema/script | 6 ++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.nextchanges/bundles/name-prefix-underscores.md b/.nextchanges/bundles/name-prefix-underscores.md index 20efbcd7a23..497c65882fc 100644 --- a/.nextchanges/bundles/name-prefix-underscores.md +++ b/.nextchanges/bundles/name-prefix-underscores.md @@ -1 +1 @@ -* Fix underscores in custom `presets.name_prefix` for schemas, registered models, and serving endpoints; existing deployments using such prefixes may recreate these resources, and schema recreation can delete data, so inspect `bundle plan` before deploying. ([#7287](https://github.com/databricks/cli/pull/7287)) +* Fix underscores in custom `presets.name_prefix` for schemas, registered models, and serving endpoints; affected schemas can rename in place, while registered models and serving endpoints can be recreated, so inspect `bundle plan` and references before deploying. ([#7287](https://github.com/databricks/cli/pull/7287)) diff --git a/acceptance/bundle/presets/name_prefix_existing_schema/output.txt b/acceptance/bundle/presets/name_prefix_existing_schema/output.txt index bb826458bc6..ad13a9b8723 100644 --- a/acceptance/bundle/presets/name_prefix_existing_schema/output.txt +++ b/acceptance/bundle/presets/name_prefix_existing_schema/output.txt @@ -11,10 +11,26 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged >>> [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged -=== A corrected prefix plans to recreate the existing schema +=== A corrected prefix plans to rename the existing schema + >>> update_file.py databricks.yml name_prefix: my_user name_prefix: my_user_ >>> [CLI] bundle plan -recreate schemas.qc +update schemas.qc + +Plan: 0 to add, 1 to change, 0 to delete, 0 unchanged -Plan: 1 to add, 0 to change, 1 to delete, 0 unchanged +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/name-prefix-existing-schema/existing/files... +Updated schemas.qc +Files: 1 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 0 unchanged + +>>> [CLI] schemas get main.my_user_qc +{ + "full_name": "main.my_user_qc", + "schema_id": "[SCHEMA_ID]" +} + +>>> [CLI] bundle plan +Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged diff --git a/acceptance/bundle/presets/name_prefix_existing_schema/script b/acceptance/bundle/presets/name_prefix_existing_schema/script index c41534842ca..8b12904936e 100644 --- a/acceptance/bundle/presets/name_prefix_existing_schema/script +++ b/acceptance/bundle/presets/name_prefix_existing_schema/script @@ -1,8 +1,12 @@ # Older CLIs resolve my_user_ to my_userqc, the name created here. trace $CLI bundle deploy trace $CLI bundle summary -o json | jq .resources.schemas.qc.id +add_repl "$($CLI schemas get main.my_userqc | jq -r .schema_id)" SCHEMA_ID trace $CLI bundle plan -title "A corrected prefix plans to recreate the existing schema" +title "A corrected prefix plans to rename the existing schema" trace update_file.py databricks.yml "name_prefix: my_user" "name_prefix: my_user_" trace $CLI bundle plan +trace $CLI bundle deploy +trace $CLI schemas get main.my_user_qc | jq '{full_name, schema_id}' +trace $CLI bundle plan