Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/cli/labs-env-non-string-attributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Fix a panic in `databricks labs` commands when a non-string SDK setting such as `DATABRICKS_DEBUG_HEADERS` or `DATABRICKS_RATE_LIMIT` is set in the environment. ([#7673](https://github.com/databricks/cli/pull/7673))
1 change: 1 addition & 0 deletions .nextchanges/cli/labs-install-without-install-hook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Fix a panic in `databricks labs install` for projects whose `labs.yml` has no `install` section. ([#7673](https://github.com/databricks/cli/pull/7673))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = false
8 changes: 8 additions & 0 deletions acceptance/labs/install-offline-no-install-hook/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

>>> [CLI] labs install foo --offline

>>> find home/.databricks/labs/foo -type f
home/.databricks/labs/foo/cache/databrickslabs-foo-releases.json
home/.databricks/labs/foo/config/login.json
home/.databricks/labs/foo/lib/labs.yml
home/.databricks/labs/foo/state/version.json
19 changes: 19 additions & 0 deletions acceptance/labs/install-offline-no-install-hook/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Offline install of a project whose labs.yml has no "install:" section,
# with a non-string SDK config attribute set via the environment.
export DATABRICKS_DEBUG_HEADERS=true

sethome ./home
LABS=home/.databricks/labs/foo
mkdir -p $LABS/lib $LABS/cache
cat > $LABS/lib/labs.yml <<'YML'
name: foo
description: project without an install hook
YML
echo '{"data":[{"tag_name":"v0.1.0"}]}' > $LABS/cache/databrickslabs-foo-releases.json

# The stack trace (if any) is cut off because it depends on the local Go setup.
errcode trace $CLI labs install foo --offline 2>&1 | sed '/^goroutine /,/^$/d'

trace find $LABS -type f | sort

rm -rf home
9 changes: 5 additions & 4 deletions cmd/labs/project/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (i *installer) Install(ctx context.Context) error {
}
w, err := i.login(ctx)
if err != nil && errors.Is(err, profile.ErrNoConfiguration) {
cfg, err := i.Installer.envAwareConfig(ctx)
cfg, err := i.metaEntrypoint(ctx).envAwareConfig(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func (i *installer) recordVersion(ctx context.Context) error {
func (i *installer) login(ctx context.Context) (*databricks.WorkspaceClient, error) {
cfg, err := i.metaEntrypoint(ctx).validLogin(i.cmd)
if errors.Is(err, ErrNoLoginConfig) {
cfg, err = i.Installer.envAwareConfig(ctx)
cfg, err = i.metaEntrypoint(ctx).envAwareConfig(ctx)
if err != nil {
return nil, err
}
Expand All @@ -181,7 +181,8 @@ func (i *installer) login(ctx context.Context) (*databricks.WorkspaceClient, err
if !i.HasAccountLevelCommands() && cfg.ConfigType() == config.AccountConfig {
return nil, errors.New("got account-level client, but no account-level commands")
}
lc := &loginConfig{Entrypoint: i.Installer.Entrypoint}
// labs.yml may have no install hook, so i.Installer can be nil.
lc := &loginConfig{Entrypoint: i.metaEntrypoint(ctx)}
w, err := lc.askWorkspace(ctx, cfg)
if err != nil {
return nil, fmt.Errorf("ask for workspace: %w", err)
Expand Down Expand Up @@ -263,7 +264,7 @@ func (i *installer) setupPythonVirtualEnvironment(ctx context.Context, w *databr
}
}
sp.Update("Installing Python library dependencies")
if i.Installer.Extras != "" {
if i.Installer != nil && i.Installer.Extras != "" {
// install main and optional dependencies
return i.installPythonDependencies(ctx, fmt.Sprintf(".[%s]", i.Installer.Extras))
}
Expand Down
7 changes: 5 additions & 2 deletions libs/env/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package env

import (
"context"
"fmt"

"github.com/databricks/databricks-sdk-go/config"
)
Expand Down Expand Up @@ -43,9 +44,11 @@ func (le *configLoader) Configure(cfg *config.Config) error {
if v == "" {
continue
}
if err := a.Set(cfg, v); err != nil {
return err
// SetS parses the string for non-string attributes; Set would panic.
if err := a.SetS(cfg, v); err != nil {
return fmt.Errorf("%s: %w", k, err)
}
break
}
}
return nil
Expand Down
19 changes: 19 additions & 0 deletions libs/env/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,22 @@ func TestLoader(t *testing.T) {
assert.Equal(t, "abc", cfg.Profile)
assert.Equal(t, "cli-env", loader.Name())
}

func TestLoaderParsesNonStringAttributes(t *testing.T) {
ctx := t.Context()
ctx = env.Set(ctx, "DATABRICKS_DEBUG_HEADERS", "true")
ctx = env.Set(ctx, "DATABRICKS_RATE_LIMIT", "42")

cfg := &config.Config{}
err := env.NewConfigLoader(ctx).Configure(cfg)
assert.NoError(t, err)

assert.True(t, cfg.DebugHeaders)
assert.Equal(t, 42, cfg.RateLimitPerSecond)
}

func TestLoaderReturnsErrorForInvalidValue(t *testing.T) {
ctx := env.Set(t.Context(), "DATABRICKS_RATE_LIMIT", "fast")
err := env.NewConfigLoader(ctx).Configure(&config.Config{})
assert.ErrorContains(t, err, "DATABRICKS_RATE_LIMIT")
}
Loading