Skip to content

Add DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE for workspace_host - #7410

Merged
pavloKozlov merged 7 commits into
mainfrom
template-helpers-profile
Nov 10, 2026
Merged

pavloKozlov merged 7 commits into
mainfrom
template-helpers-profile

Conversation

@pavloKozlov

@pavloKozlov pavloKozlov commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Changes

Adds DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE. When it names a profile, the workspace_host template helper returns that profile's host instead of the selected profile's host. The profile must have the selected profile's workspace ID, otherwise rendering fails. Like the SDK, the ID can also come from ?w= or ?o= in the profile's host. Everything else, including .workspace and the other helpers, keeps the selected profile. The profile is read once from the config file, so there is no extra request.

Why

DABs in the Workspace will select the profile for the page's host, which can be a host shared by several workspaces, so templates that use .workspace get that host with ?w=<id>. Existing custom templates that use workspace_host must keep generating the workspace's own host. Without the variable nothing changes.

Tests

A unit test covers the override and each error. The workspace_variable acceptance test renders a schema and runs init with the runner's profiles, and shows the errors. On dogfood serverless I checked that templates render the same values through the shared host, and that a bundle with the workspace's own host still validates with the runner's profiles.

This pull request and its description were written by Isaac.

@github-actions github-actions Bot added the DABs DABs related issues label Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Commit: a3cd02cc0 | Workflow run

Regression test report

Selected 1 changed tests (limit=20, 0 not selected)

2 tests: regression=2 unreleased=0 coverage=0 failing=0
test branch main (b694c4c) latest (v1.25.0)
TestAccept/bundle/templates-machinery/workspace_variable/runtime/DMS= ✅ ❌ ❌
TestAccept/bundle/templates-machinery/workspace_variable/runtime/DMS=true ✅ ❌ ❌
TestAccept/bundle/templates-machinery/workspace_variable/runtime/DMS=: branch ✅ | main (b694c4c) ❌ | latest (v1.25.0) ❌

main (b694c4c):

acceptance_test.go:1345: Diff:
        --- bundle/templates-machinery/workspace_variable/runtime/output.txt
        +++ /tmp/TestAcceptbundletemplates-machineryworkspace_variableruntime385081504/002/output.txt
        @@ -225,41 +225,28 @@
         
         >>> DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE=workspace_classic_id [CLI] bundle debug render-template-schema ./helpers --profile workspace_custom_host
         {
        -  "welcome_message": "workspace_host: [DATABRICKS_URL], URL: [CUSTOM_HOST]?w=[WORKSPACE_ID]",
        +  "welcome_message": "workspace_host: [CUSTOM_HOST], URL: [CUSTOM_HOST]?w=[WORKSPACE_ID]",
           "success_message": null,
           "properties": {
             "host": {
               "description": "Host for [USERNAME]",
        -      "default": "[DATABRICKS_URL]"
        +      "default": "[CUSTOM_HOST]"
             }
           }
         }
         
         >>> DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE=workspace_classic_id [CLI] bundle init ./helpers --profile workspace_custom_host
        -workspace_host: [DATABRICKS_URL], URL: [CUSTOM_HOST]?w=[WORKSPACE_ID]
        +workspace_host: [CUSTOM_HOST], URL: [CUSTOM_HOST]?w=[WORKSPACE_ID]
         ✨ Successfully initialized template
        -workspace_host: [DATABRICKS_URL]
        -host: [DATABRICKS_URL]
        +workspace_host: [CUSTOM_HOST]
        +host: [CUSTOM_HOST]
         URL: [CUSTOM_HOST]?w=[WORKSPACE_ID]
         user_name: [USERNAME]
         
         >>> DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE=other_workspace musterr [CLI] bundle init ./helpers --profile workspace_custom_host
        -Error: template: :1:19: executing "" at <workspace_host>: error calling workspace_host: profile "other_workspace" from DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE has workspace ID "1234", but the selected profile has workspace ID "[WORKSPACE_ID]"
        -
        ->>> DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE=missing musterr [CLI] bundle debug render-template-schema ./helpers --profile workspace_custom_host
        -Error: property host default: failed to render template "{{ workspace_host }}": template: base:1:3: executing "base" at <workspace_host>: error calling workspace_host: profile "missing" from DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE not found or has no host
        -
        -=== ID
        -
        ->>> [CLI] bundle init ./id --profile workspace_classic
        +workspace_host: [CUSTOM_HOST], URL: [CUSTOM_HOST]?w=[WORKSPACE_ID]
         ✨ Successfully initialized template
        -ID: [WORKSPACE_ID]
         
        ->>> [CLI] bundle init ./id --profile workspace_custom_host
        -✨ Successfully initialized template
        -ID: [WORKSPACE_ID]
        +Unexpected success
         
        ->>> musterr [CLI] bundle init ./id --profile no_workspace_id
        -Error: failed to compute file content for id.txt.tmpl. template: :1:17: executing "" at <.workspace.ID>: error calling ID: cannot determine workspace ID, please set workspace_id in the configuration profile, the DATABRICKS_WORKSPACE_ID environment variable, or workspace.workspace_id in the bundle
        -
        ->>> print_requests.py --get --oneline ^//telemetry-ext
        +Exit code: 1
        
    acceptance_test.go:1135: Test produced unexpected files:
        helpers.txt

latest (v1.25.0): same output as main (b694c4c)

TestAccept/bundle/templates-machinery/workspace_variable/runtime/DMS=true: branch ✅ | main (b694c4c) ❌ | latest (v1.25.0) ❌

main (b694c4c):

acceptance_test.go:1345: Diff:
        --- bundle/templates-machinery/workspace_variable/runtime/output.txt
        +++ /tmp/TestAcceptbundletemplates-machineryworkspace_variableruntime2551528425/002/output.txt
        @@ -225,41 +225,28 @@
         
         >>> DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE=workspace_classic_id [CLI] bundle debug render-template-schema ./helpers --profile workspace_custom_host
         {
        -  "welcome_message": "workspace_host: [DATABRICKS_URL], URL: [CUSTOM_HOST]?w=[WORKSPACE_ID]",
        +  "welcome_message": "workspace_host: [CUSTOM_HOST], URL: [CUSTOM_HOST]?w=[WORKSPACE_ID]",
           "success_message": null,
           "properties": {
             "host": {
               "description": "Host for [USERNAME]",
        -      "default": "[DATABRICKS_URL]"
        +      "default": "[CUSTOM_HOST]"
             }
           }
         }
         
         >>> DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE=workspace_classic_id [CLI] bundle init ./helpers --profile workspace_custom_host
        -workspace_host: [DATABRICKS_URL], URL: [CUSTOM_HOST]?w=[WORKSPACE_ID]
        +workspace_host: [CUSTOM_HOST], URL: [CUSTOM_HOST]?w=[WORKSPACE_ID]
         ✨ Successfully initialized template
        -workspace_host: [DATABRICKS_URL]
        -host: [DATABRICKS_URL]
        +workspace_host: [CUSTOM_HOST]
        +host: [CUSTOM_HOST]
         URL: [CUSTOM_HOST]?w=[WORKSPACE_ID]
         user_name: [USERNAME]
         
         >>> DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE=other_workspace musterr [CLI] bundle init ./helpers --profile workspace_custom_host
        -Error: template: :1:19: executing "" at <workspace_host>: error calling workspace_host: profile "other_workspace" from DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE has workspace ID "1234", but the selected profile has workspace ID "[WORKSPACE_ID]"
        -
        ->>> DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE=missing musterr [CLI] bundle debug render-template-schema ./helpers --profile workspace_custom_host
        -Error: property host default: failed to render template "{{ workspace_host }}": template: base:1:3: executing "base" at <workspace_host>: error calling workspace_host: profile "missing" from DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE not found or has no host
        -
        -=== ID
        -
        ->>> [CLI] bundle init ./id --profile workspace_classic
        +workspace_host: [CUSTOM_HOST], URL: [CUSTOM_HOST]?w=[WORKSPACE_ID]
         ✨ Successfully initialized template
        -ID: [WORKSPACE_ID]
         
        ->>> [CLI] bundle init ./id --profile workspace_custom_host
        -✨ Successfully initialized template
        -ID: [WORKSPACE_ID]
        +Unexpected success
         
        ->>> musterr [CLI] bundle init ./id --profile no_workspace_id
        -Error: failed to compute file content for id.txt.tmpl. template: :1:17: executing "" at <.workspace.ID>: error calling ID: cannot determine workspace ID, please set workspace_id in the configuration profile, the DATABRICKS_WORKSPACE_ID environment variable, or workspace.workspace_id in the bundle
        -
        ->>> print_requests.py --get --oneline ^//telemetry-ext
        +Exit code: 1
        
    acceptance_test.go:1135: Test produced unexpected files:
        helpers.txt
FAIL

latest (v1.25.0): same output as main (b694c4c)

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: a3cd02c

Run: 42791020851

Env ✅​pass 🙈​skip Time
✅​ aws linux-2core-8gb 271 16 3:49
✅​ aws-windows-latest-4core-16gb 273 14 3:09
✅​ azure linux-2core-8gb 270 16 3:42
✅​ azure-windows-latest-4core-16gb 272 14 3:16
✅​ gcp linux-2core-8gb 271 16 3:53
✅​ gcp-windows-latest-4core-16gb 273 14 2:41
Top 3 slowest tests (at least 2 minutes):
duration env testname
3:09 azure-windows-latest-4core-16gb TestAccept
3:04 aws-windows-latest-4core-16gb TestAccept
2:30 gcp-windows-latest-4core-16gb TestAccept

@pavloKozlov pavloKozlov changed the title Add DATABRICKS_BUNDLE_INIT_HELPERS_PROFILE for template helpers Add DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE for workspace_host Nov 9, 2026
@pavloKozlov
pavloKozlov marked this pull request as ready for review November 9, 2026 16:16
@pavloKozlov
pavloKozlov requested review from a team as code owners November 9, 2026 16:16
pavloKozlov and others added 6 commits November 9, 2026 19:04
When the variable names a profile, the template helpers that read or call
the workspace (workspace_host, user_name, default_catalog and others) use
that profile in bundle init and bundle debug render-template-schema.
.workspace and all other requests, including the writes of the generated
files, keep the selected profile. The command fails if the two profiles
have different workspace IDs.

DABs in the Workspace selects the profile for the host of the page, which
can be a host shared by several workspaces, and points the helpers at the
workspace's own host. Templates that use workspace_host keep their output.

Co-authored-by: Isaac <no-reply@databricks.com>
…eads

Move the profile loading to root.MustWorkspaceClientForTemplate so it shares
applyProfileAuthPrecedence with --profile, and use it in pipelines init too.
The warehouse_path prompt now reads through the helpers profile as well.
Fail when the helpers profile has no workspace ID instead of skipping the
check.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Replace DATABRICKS_BUNDLE_INIT_HELPERS_PROFILE with
DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE. Only the workspace_host helper
reads the named profile, from the config file, and returns its host. The
other helpers, the warehouse_path prompt and .workspace keep the selected
profile, so no second client or command wiring is needed.

Co-authored-by: Isaac <no-reply@databricks.com>
Reuse the profile package's host canonicalization (now exported as
profile.CanonicalizeHost), reject a profile host that doesn't parse, label
both workspace IDs in the mismatch error, and cover a missing config file.

Co-authored-by: Isaac <no-reply@databricks.com>
…e ID

Co-authored-by: Isaac <no-reply@databricks.com>
@pavloKozlov
pavloKozlov force-pushed the template-helpers-profile branch from 5325cb0 to 9b70d33 Compare November 9, 2026 19:20
Comment thread libs/template/helpers.go Outdated
return "", fmt.Errorf("profile %q from %s not found or has no host", name, workspaceHostProfileEnvVar)
}
p := profiles[0]
if p.WorkspaceID == "" || p.WorkspaceID == profile.WorkspaceIDNone || p.WorkspaceID != w.Config.WorkspaceID {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will this work for a profile whose host carries the ID as ?o=<id> and has no workspace_id? The SDK treats that host as having the ID (fixHostIfNeeded promotes it), but here p.WorkspaceID is "" so the profile is rejected. Fine if the UI always writes workspace_id into the profile, just checking it's intentional.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI always pass workspace_id in a profile but I updated the code so it would also handle ?w= or ?o=.

Comment thread libs/template/helpers.go
// DABs in the Workspace selects the profile for the host of the page, which can be a host shared
// by several workspaces, and sets this to a profile for the workspace's own host, so that
// templates that use workspace_host keep generating that host.
const workspaceHostProfileEnvVar = "DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST_PROFILE"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was passing the host directly considered (something like DATABRICKS_BUNDLE_INIT_WORKSPACE_HOST=<host>)? The only thing we read from the profile is its host, and with the indirection the UI has to write a second profile just for this. Or is the profile needed so we can check the workspace ID against the selected one?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need both host and workspace id. UI writes multiple profiles anyway, so there is no extra work there.

Comment thread libs/template/helpers.go
return w.Config.Host, nil
}

profiles, err := profile.GetProfiler(ctx).LoadProfiles(ctx, profile.WithName(name))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this re-reads and parses .databrickscfg on every workspace_host call (schema defaults, welcome message, each template file). Worth caching the result like cachedUser does?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

…ile once

Like the SDK does for the selected profile, take the workspace ID from ?w= or
?o= in the host when the profile has no workspace_id. Cache the workspace_host
result so templates don't read the config file on every call.

Co-authored-by: Isaac <no-reply@databricks.com>
@pavloKozlov
pavloKozlov added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 9605618 Nov 10, 2026
28 checks passed
@pavloKozlov
pavloKozlov deleted the template-helpers-profile branch November 10, 2026 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DABs DABs related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants