Skip to content

Commit 3d63763

Browse files
authored
pipelines: fix auto-selection in "pipelines run" (#4245)
## Changes Fix auto-selection in "pipelines run" command. Previously, if bundle had a job and a pipeline, auto-selection didn't work because both are considered runnable. This is true, for example, for lakeflow-pipelines template. It's not intended because "pipelines run" command should only be applicable to pipelines. ## Why Fixing not correct behaviour ## Tests Acceptance tests
1 parent ec58ff2 commit 3d63763

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

acceptance/pipelines/run/run-pipeline/databricks.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ resources:
88
libraries:
99
- file:
1010
path: pipeline_file.py
11+
# job is runnable, but doesn't impact auto-selection of pipeline
12+
jobs:
13+
my_job:
14+
name: "My Job"

acceptance/pipelines/run/run-pipeline/output.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-pipeline-run/
44
Deploying resources...
55
Updating deployment state...
66
Deployment complete!
7+
View your job my_job here: [DATABRICKS_URL]/jobs/[NUMID]?o=[NUMID]
78
View your pipeline my_pipeline here: [DATABRICKS_URL]/pipelines/[UUID]?o=[NUMID]
89

910
=== Run pipeline

cmd/pipelines/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ Refreshes all tables in the pipeline unless otherwise specified.`,
351351
}
352352

353353
if len(args) == 0 {
354-
completions := bundleresources.Completions(b, run.IsRunnable)
354+
completions := bundleresources.Completions(b, isPipeline)
355355
return maps.Keys(completions), cobra.ShellCompDirectiveNoFileComp
356356
} else {
357357
// If we know the resource to run, we can complete additional positional arguments.

cmd/pipelines/utils.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@ func promptResource(ctx context.Context, b *bundle.Bundle, filters ...resources.
4242
// autoSelectSinglePipeline checks if there's exactly one pipeline resource in the bundle and returns its key.
4343
// Returns empty string if there's not exactly one pipeline.
4444
func autoSelectSinglePipeline(b *bundle.Bundle) string {
45-
completions := resources.Completions(b, run.IsRunnable)
45+
completions := resources.Completions(b, isPipeline)
4646
if len(completions) == 1 {
47-
for key, ref := range completions {
48-
if _, ok := ref.Resource.(*configresources.Pipeline); ok {
49-
return key
50-
}
47+
for key := range completions {
48+
return key
5149
}
5250
}
5351
return ""
@@ -334,3 +332,12 @@ func fetchPipelineUpdates(ctx context.Context, w *databricks.WorkspaceClient, st
334332

335333
return updates, nil
336334
}
335+
336+
func isPipeline(ref resources.Reference) bool {
337+
switch ref.Resource.(type) {
338+
case *configresources.Pipeline:
339+
return true
340+
default:
341+
return false
342+
}
343+
}

0 commit comments

Comments
 (0)