Skip to content

Commit

Permalink
Fixed seg fault when specifying environment key for tasks (#1443)
Browse files Browse the repository at this point in the history
## Changes
Fixed seg fault when specifying environment key for tasks
  • Loading branch information
andrewnester authored May 21, 2024
1 parent 09aa3cb commit 3f8036f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bundle/artifacts/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ func uploadArtifact(ctx context.Context, b *bundle.Bundle, a *config.Artifact, u

for i := range job.Environments {
env := &job.Environments[i]
if env.Spec == nil {
continue
}

for j := range env.Spec.Dependencies {
lib := env.Spec.Dependencies[j]
if isArtifactMatchLibrary(f, lib, b) {
Expand Down
4 changes: 4 additions & 0 deletions bundle/libraries/libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func FindAllEnvironments(b *bundle.Bundle) map[string]([]jobs.JobEnvironment) {

func isEnvsWithLocalLibraries(envs []jobs.JobEnvironment) bool {
for _, e := range envs {
if e.Spec == nil {
continue
}

for _, l := range e.Spec.Dependencies {
if IsEnvironmentDependencyLocal(l) {
return true
Expand Down
4 changes: 4 additions & 0 deletions bundle/libraries/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func validateTaskLibraries(libs []compute.Library, b *bundle.Bundle) error {

func validateEnvironments(envs []jobs.JobEnvironment, b *bundle.Bundle) error {
for _, env := range envs {
if env.Spec == nil {
continue
}

for _, dep := range env.Spec.Dependencies {
matches, err := filepath.Glob(filepath.Join(b.RootPath, dep))
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions bundle/tests/enviroment_key_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package config_tests

import (
"context"
"testing"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/libraries"
"github.com/stretchr/testify/require"
)

func TestEnvironmentKeySupported(t *testing.T) {
_, diags := loadTargetWithDiags("./python_wheel/environment_key", "default")
require.Empty(t, diags)
}

func TestEnvironmentKeyProvidedAndNoPanic(t *testing.T) {
b, diags := loadTargetWithDiags("./environment_key_only", "default")
require.Empty(t, diags)

diags = bundle.Apply(context.Background(), b, libraries.ValidateLocalLibrariesExist())
require.Empty(t, diags)
}
16 changes: 16 additions & 0 deletions bundle/tests/environment_key_only/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
bundle:
name: environment_key_only

resources:
jobs:
test_job:
name: "My Wheel Job"
tasks:
- task_key: TestTask
existing_cluster_id: "0717-132531-5opeqon1"
python_wheel_task:
package_name: "my_test_code"
entry_point: "run"
environment_key: "test_env"
environments:
- environment_key: "test_env"

0 comments on commit 3f8036f

Please sign in to comment.