Skip to content

Commit 2c2336a

Browse files
committed
fix: merge extra resources into existing context
Signed-off-by: Amund Tenstad <github@amund.io>
1 parent 9f654e9 commit 2c2336a

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

fn.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"maps"
56
"reflect"
67
"sort"
78

@@ -80,12 +81,20 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest)
8081
return rsp, nil
8182
}
8283

83-
s, err := structpb.NewStruct(verifiedExtras)
84+
out, err := structpb.NewStruct(verifiedExtras)
8485
if err != nil {
8586
response.Fatal(rsp, errors.Wrapf(err, "cannot create new Struct from extra resources output"))
8687
return rsp, nil
8788
}
88-
response.SetContextKey(rsp, in.Spec.Context.GetKey(), structpb.NewStructValue(s))
89+
90+
if v, ok := request.GetContextKey(req, in.Spec.Context.GetKey()); ok {
91+
if s := v.GetStructValue(); s != nil {
92+
maps.Copy(s.Fields, out.Fields)
93+
out = s
94+
}
95+
}
96+
97+
response.SetContextKey(rsp, in.Spec.Context.GetKey(), structpb.NewStructValue(out))
8998

9099
return rsp, nil
91100
}

0 commit comments

Comments
 (0)