Skip to content

Commit e15b8f1

Browse files
Fix bundle init not working in Azure Government (#4286)
## Changes <!-- Brief summary of your changes that is easy to understand --> Fixes #2584 by handling the `Bad Target: /api/2.1/unity-catalog/current-metastore-assignment` error present in Databricks Workspaces deployed in Azure Government regions. ## Why <!-- Why are these changes needed? Provide the context that the reviewer might be missing. For example, were there any decisions behind the change that are not reflected in the code itself? --> Using `databricks bundle init` does not currently work in Azure Government regions. ## Tests <!-- How have you tested the changes? --> An acceptance test has been created for this scenario. <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. --> --------- Co-authored-by: Andrew Nester <andrew.nester.dev@gmail.com>
1 parent e7fa565 commit e15b8f1

File tree

7 files changed

+36
-1
lines changed

7 files changed

+36
-1
lines changed

NEXT_CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
* Log artifact build output in debug mode ([#4208](https://github.com/databricks/cli/pull/4208))
77

88
### Dependency updates
9+
10+
### Bundles
11+
* Fix bundle init not working in Azure Government ([#4286](https://github.com/databricks/cli/pull/4286))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"project_name": "my_default_python",
3+
"include_notebook": "yes",
4+
"include_dlt": "yes",
5+
"include_python": "yes",
6+
"serverless": "no"
7+
}

acceptance/bundle/templates/default-python/azure-government/out.test.toml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
>>> [CLI] bundle init default-python --config-file ./input.json --output-dir output
3+
Welcome to the default Python template for Databricks Asset Bundles!
4+
5+
Answer the following questions to customize your project.
6+
You can always change your configuration in the databricks.yml file later.
7+
8+
Note that [DATABRICKS_URL] is used for initialization.
9+
(For information on how to change your profile, see https://docs.databricks.com/dev-tools/cli/profiles.html.)
10+
11+
✨ Your new project has been created in the 'my_default_python' directory!
12+
13+
To get started, refer to the project README.md file and the documentation at https://docs.databricks.com/dev-tools/bundles/index.html.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trace $CLI bundle init default-python --config-file ./input.json --output-dir output
2+
3+
rm -rf output
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[[Server]]
2+
Pattern = "GET /api/2.1/unity-catalog/current-metastore-assignment"
3+
Response.StatusCode = 404
4+
Response.Body = "{ \"error\": \"Bad Target: /api/2.1/unity-catalog/current-metastore-assignment\" }"

libs/template/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func loadHelpers(ctx context.Context) template.FuncMap {
148148
metastore, err := w.Metastores.Current(ctx)
149149
if err != nil {
150150
var aerr *apierr.APIError
151-
if errors.As(err, &aerr) && slices.Contains(metastoreDisabledErrorCodes, aerr.ErrorCode) {
151+
if errors.As(err, &aerr) && (slices.Contains(metastoreDisabledErrorCodes, aerr.ErrorCode) || aerr.Message == "Bad Target: /api/2.1/unity-catalog/current-metastore-assignment") {
152152
// Ignore: access denied or workspace doesn't have a metastore assigned
153153
empty_default := ""
154154
cachedCatalog = &empty_default

0 commit comments

Comments
 (0)