Skip to content

Propagate auth env to experimental.python subprocess#5074

Merged
simonfaltum merged 10 commits intomainfrom
simonfaltum/pydabs-profile-env
May 8, 2026
Merged

Propagate auth env to experimental.python subprocess#5074
simonfaltum merged 10 commits intomainfrom
simonfaltum/pydabs-profile-env

Conversation

@simonfaltum
Copy link
Copy Markdown
Member

Why

When bundle deploy / bundle validate runs with a profile set (via --profile, DATABRICKS_CONFIG_PROFILE, or workspace.profile in databricks.yml) and the bundle uses experimental.python, the Python subprocess does not inherit DATABRICKS_CONFIG_PROFILE. The Databricks SDK inside Python then re-invokes the CLI via databricks auth token --host <host> without a profile, and fails with a multi-profile ambiguity error when ~/.databrickscfg has several profiles sharing the same host.

This is the remaining scenario on #4649. The Terraform path was fixed in #4624; the experimental.python path was missed because the Python mutator spawned its subprocess via process.Background without any auth env setup.

Changes

Before: bundle/config/mutator/python/python_mutator.go called process.Background with no environment propagation. The Python subprocess only saw whatever env vars the user happened to export; DATABRICKS_CONFIG_PROFILE from --profile or databricks.yml was silently dropped.

Now: The mutator calls b.AuthEnv(ctx) (same call the Terraform path uses) and passes the resulting map through process.WithEnvs(...). The Python SDK and any subprocesses it spawns now see the same auth configuration as the CLI itself.

Test plan

  • New unit test TestPythonMutator_propagatesAuthEnv asserts that DATABRICKS_CONFIG_PROFILE is present in the Python subprocess env when workspace.profile is set.
  • Existing python mutator tests pass (go test ./bundle/config/mutator/python/).
  • Full bundle test suite passes (go test ./bundle/...).
  • make checks and make lint clean.

When workspace.profile is set (via --profile, DATABRICKS_CONFIG_PROFILE,
or workspace.profile in databricks.yml), bundle commands that run the
experimental.python phase need to pass the resolved profile through to
the Python subprocess. Otherwise the Databricks SDK inside Python
re-invokes the CLI via `databricks auth token --host <host>` without a
profile hint, and the CLI cannot disambiguate profiles sharing the same
host in ~/.databrickscfg.

Mirrors what the Terraform phase already does via b.AuthEnv() and fixes
the remaining path reported on issue #4649.

Co-authored-by: Isaac
@simonfaltum simonfaltum temporarily deployed to test-trigger-is May 6, 2026 09:27 — with GitHub Actions Inactive
@simonfaltum simonfaltum temporarily deployed to test-trigger-is May 6, 2026 09:27 — with GitHub Actions Inactive
assert.Equal(t, int64(1), b.Metrics.PythonUpdatedResourcesCount)
}

func TestPythonMutator_propagatesAuthEnv(t *testing.T) {
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: we could make it an acceptance test instead

Copy link
Copy Markdown
Member Author

@simonfaltum simonfaltum May 7, 2026

Choose a reason for hiding this comment

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

Done in 9f0f669, moved to acceptance/bundle/python/propagates-auth-env. Mutator captures DATABRICKS_CONFIG_PROFILE from os.environ and writes it to a file we then cat in the script, so it asserts the env actually reaches the python subprocess.

Replace the unit test that stubbed process.Background with an acceptance
test under acceptance/bundle/python/propagates-auth-env/ that runs a real
python mutator and asserts DATABRICKS_CONFIG_PROFILE is captured from the
subprocess env.

Co-authored-by: Isaac
@simonfaltum simonfaltum temporarily deployed to test-trigger-is May 7, 2026 11:56 — with GitHub Actions Inactive
@simonfaltum simonfaltum temporarily deployed to test-trigger-is May 7, 2026 11:56 — with GitHub Actions Inactive
@simonfaltum simonfaltum temporarily deployed to test-trigger-is May 7, 2026 14:13 — with GitHub Actions Inactive
@simonfaltum simonfaltum temporarily deployed to test-trigger-is May 7, 2026 14:13 — with GitHub Actions Inactive
@simonfaltum simonfaltum temporarily deployed to test-trigger-is May 8, 2026 08:35 — with GitHub Actions Inactive
@simonfaltum simonfaltum temporarily deployed to test-trigger-is May 8, 2026 08:35 — with GitHub Actions Inactive
@simonfaltum simonfaltum temporarily deployed to test-trigger-is May 8, 2026 10:27 — with GitHub Actions Inactive
@simonfaltum simonfaltum temporarily deployed to test-trigger-is May 8, 2026 10:27 — with GitHub Actions Inactive
@simonfaltum simonfaltum merged commit 942e91c into main May 8, 2026
22 of 23 checks passed
@simonfaltum simonfaltum deleted the simonfaltum/pydabs-profile-env branch May 8, 2026 12:21
# so the SDK inside python re-invokes the CLI without a profile and fails on
# multi-profile ambiguity.
trace cat captured_env.txt
echo ""
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: let Python write the newline. I was confused as to why this was necessary.

export DATABRICKS_CONFIG_FILE=.databrickscfg
unset DATABRICKS_HOST
unset DATABRICKS_TOKEN
unset DATABRICKS_CONFIG_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.

Can use a comment why they need to be cleared.

Comment thread NEXT_CHANGELOG.md

### Bundles

* Propagate authentication environment (including `DATABRICKS_CONFIG_PROFILE`) to the `experimental.python` subprocess so bundle validate/deploy no longer fails with a multi-profile host ambiguity error when several profiles in `~/.databrickscfg` share the same host.
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.

"to Python subprocesses" -- the Python support is no longer experimental.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants