Skip to content

Commit c924b26

Browse files
authored
fix: assume the flowfile context when expanding refs for serial/parallel (#322)
Currently the current context is being used when running a serial or parallel executable with incomplete references. This causes issues when trying to run an executable from another workspace. This change makes it so that the parent executable's workspace and namespace is used for the ref instead.
1 parent a222fdc commit c924b26

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

internal/context/context.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ func ExpandRef(ctx *Context, ref executable.Ref) executable.Ref {
214214
return executable.NewRef(executable.NewExecutableID(ws, ns, name), ref.Verb())
215215
}
216216

217+
func ExpandRefFromParent(parent *executable.Executable, ref executable.Ref) executable.Ref {
218+
id := ref.ID()
219+
ws, ns, name := executable.MustParseExecutableID(id)
220+
if ws == "" || ws == executable.WildcardWorkspace {
221+
ws = parent.Workspace()
222+
}
223+
if ns == "" {
224+
ns = parent.Namespace()
225+
}
226+
return executable.NewRef(executable.NewExecutableID(ws, ns, name), ref.Verb())
227+
}
228+
217229
func currentWorkspace(cfg *config.Config) (*workspace.Workspace, error) {
218230
ws, err := cfg.CurrentWorkspaceName()
219231
if err != nil {

internal/runner/parallel/parallel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func handleExec(
118118
switch {
119119
case len(refConfig.Ref) > 0:
120120
var err error
121-
exec, err = execUtils.ExecutableForRef(ctx, refConfig.Ref)
121+
exec, err = execUtils.ExecutableForRef(ctx, parent, refConfig.Ref)
122122
if err != nil {
123123
return err
124124
}

internal/runner/serial/serial.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func handleExec(
107107
switch {
108108
case refConfig.Ref != "":
109109
var err error
110-
exec, err = execUtils.ExecutableForRef(ctx, refConfig.Ref)
110+
exec, err = execUtils.ExecutableForRef(ctx, parent, refConfig.Ref)
111111
if err != nil {
112112
return err
113113
}

internal/templates/templates.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func runExecutables(
131131
if err != nil {
132132
return errors.Wrap(err, fmt.Sprintf("unable to process %s executable %d", stage, i))
133133
}
134-
exec, err = execUtils.ExecutableForRef(ctx, executable.Ref(ref.String()))
134+
exec, err = execUtils.ExecutableForRef(ctx, nil, executable.Ref(ref.String()))
135135
if err != nil {
136136
return err
137137
}

internal/utils/executables/executables.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@ import (
88
"github.com/flowexec/flow/types/executable"
99
)
1010

11-
func ExecutableForRef(ctx *context.Context, ref executable.Ref) (*executable.Executable, error) {
12-
executableRef := context.ExpandRef(ctx, ref)
11+
func ExecutableForRef(
12+
ctx *context.Context,
13+
parent *executable.Executable,
14+
ref executable.Ref,
15+
) (*executable.Executable, error) {
16+
var executableRef executable.Ref
17+
if parent != nil {
18+
executableRef = context.ExpandRefFromParent(parent, ref)
19+
} else {
20+
executableRef = context.ExpandRef(ctx, ref)
21+
}
1322
exec, err := ctx.ExecutableCache.GetExecutableByRef(executableRef)
1423
if err != nil {
1524
return nil, err

0 commit comments

Comments
 (0)