Skip to content

Commit

Permalink
fix: external_module.go with sinks/sources build failures (#1132)
Browse files Browse the repository at this point in the history
Fixes #1095

Sink & Source verbs would have a schema like
```
verb returnsUser(Unit) two.UserResponse
```
but the scaffolded `external_module.go` version of it would be:
```
func ReturnsUser(ctx context.Context) (UserResponse, error)
```

When generating imports, we were finding `schema.Unit` in the verb which
triggered an inclusion of ftl
This caused the exernal module to fail to build because ftl was not
being used by the generated code.

This fix now skips any unit in the schema if the parent is a verb
  • Loading branch information
matt2e authored Mar 25, 2024
1 parent 0764aa2 commit 16588c5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
6 changes: 6 additions & 0 deletions backend/schema/visit.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ func VisitExcludingMetadataChildren(n Node, visit func(n Node, next func() error
return visit(n, func() error {
if _, ok := n.(Metadata); !ok {
for _, child := range n.schemaChildren() {
_, isParentVerb := n.(*Verb)
_, isChildUnit := child.(*Unit)
if isParentVerb && isChildUnit {
// Skip visiting children of a verb that are units as the scaffolded code will not inclue them
continue
}
if err := VisitExcludingMetadataChildren(child, visit); err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion buildengine/build_go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ package other
import (
"context"
"github.com/TBD54566975/ftl/go-runtime/ftl"
)
var _ = context.Background
Expand Down
2 changes: 1 addition & 1 deletion go-runtime/compile/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestExtractModuleSchemaTwo(t *testing.T) {
verb callsTwo(two.Payload<String>) two.Payload<String>
+calls two.two
verb returnsUser(Unit) two.UserResponse?
verb returnsUser(Unit) two.UserResponse
verb two(two.Payload<String>) two.Payload<String>
}
Expand Down
6 changes: 3 additions & 3 deletions go-runtime/compile/testdata/two/two.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func CallsTwo(ctx context.Context, req Payload[string]) (Payload[string], error)
}

//ftl:export
func ReturnsUser(ctx context.Context) (ftl.Option[UserResponse], error) {
return ftl.Some[UserResponse](UserResponse{
func ReturnsUser(ctx context.Context) (UserResponse, error) {
return UserResponse{
User: User{
Name: "John Doe",
},
}), nil
}, nil
}

0 comments on commit 16588c5

Please sign in to comment.