From aed411cc9094a60170c00a4f70fc2f79beffaf95 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Wed, 30 Aug 2023 15:48:51 +0200 Subject: [PATCH] Fixed panic from Python transform when no python wheel tasks defined --- bundle/python/transform.go | 3 +++ bundle/python/transform_test.go | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/bundle/python/transform.go b/bundle/python/transform.go index 69bb5766f1..875d051910 100644 --- a/bundle/python/transform.go +++ b/bundle/python/transform.go @@ -69,6 +69,9 @@ func (t *pythonTrampoline) GetTasks(b *bundle.Bundle) []mutator.TaskWithJobKey { tasks := r.Jobs[k].JobSettings.Tasks for i := range tasks { task := &tasks[i] + if task.PythonWheelTask == nil { + continue + } result = append(result, mutator.TaskWithJobKey{ JobKey: k, Task: task, diff --git a/bundle/python/transform_test.go b/bundle/python/transform_test.go index 1baebfc8e6..135cc38622 100644 --- a/bundle/python/transform_test.go +++ b/bundle/python/transform_test.go @@ -1,9 +1,13 @@ package python import ( + "context" "strings" "testing" + "github.com/databricks/cli/bundle" + "github.com/databricks/cli/bundle/config" + "github.com/databricks/cli/bundle/config/resources" "github.com/databricks/databricks-sdk-go/service/jobs" "github.com/stretchr/testify/require" ) @@ -64,3 +68,34 @@ func TestGenerateBoth(t *testing.T) { require.Error(t, err) require.ErrorContains(t, err, "not allowed to pass both paramaters and named_parameters") } + +func TestNoPanicWithNoPythonWheelTasks(t *testing.T) { + tmpDir := t.TempDir() + b := &bundle.Bundle{ + Config: config.Root{ + Path: tmpDir, + Bundle: config.Bundle{ + Target: "development", + }, + Resources: config.Resources{ + Jobs: map[string]*resources.Job{ + "test": { + Paths: resources.Paths{ + ConfigFilePath: tmpDir, + }, + JobSettings: &jobs.JobSettings{ + Tasks: []jobs.Task{ + { + TaskKey: "notebook_task", + NotebookTask: &jobs.NotebookTask{}}, + }, + }, + }, + }, + }, + }, + } + trampoline := TransformWheelTask() + err := bundle.Apply(context.Background(), b, trampoline) + require.NoError(t, err) +}