Skip to content

Commit

Permalink
[flytepropeller][compiler] Error Handling when Type is not found (fly…
Browse files Browse the repository at this point in the history
…teorg#5612)

* FlytePropeller Compiler Avoid Crash when Type not found

Signed-off-by: Future-Outlier <[email protected]>

* Update pingsu's error message advices

Signed-off-by: Future-Outlier <[email protected]>
Co-authored-by: pingsutw  <[email protected]>

* fix lint

Signed-off-by: Future-Outlier <[email protected]>

* Trigger CI

Signed-off-by: Future-Outlier <[email protected]>

* Trigger CI

Signed-off-by: Future-Outlier <[email protected]>

---------

Signed-off-by: Future-Outlier <[email protected]>
Co-authored-by: pingsutw <[email protected]>
Signed-off-by: Bugra Gedik <[email protected]>
  • Loading branch information
2 people authored and bgedik committed Aug 15, 2024
1 parent d8e7491 commit 021c606
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"github.com/flyteorg/flyte/flytestdlib/utils"
)

const (
foo = "foo"
)

var lpApplicationConfig = testutils.GetApplicationConfigWithDefaultDomains()

func getWorkflowInterface() *core.TypedInterface {
Expand Down Expand Up @@ -344,7 +348,7 @@ func TestValidateSchedule_KickoffTimeArgPointsAtWrongType(t *testing.T) {
request := testutils.GetLaunchPlanRequestWithDeprecatedCronSchedule("* * * * * *")
inputMap := &core.ParameterMap{
Parameters: map[string]*core.Parameter{
"foo": {
foo: {
Var: &core.Variable{
Type: &core.LiteralType{Type: &core.LiteralType_Simple{Simple: core.SimpleType_STRING}},
},
Expand All @@ -354,7 +358,7 @@ func TestValidateSchedule_KickoffTimeArgPointsAtWrongType(t *testing.T) {
},
},
}
request.Spec.EntityMetadata.Schedule.KickoffTimeInputArg = "foo"
request.Spec.EntityMetadata.Schedule.KickoffTimeInputArg = foo

err := validateSchedule(request, inputMap)
assert.NotNil(t, err)
Expand All @@ -364,7 +368,7 @@ func TestValidateSchedule_NoRequired(t *testing.T) {
request := testutils.GetLaunchPlanRequestWithDeprecatedCronSchedule("* * * * * *")
inputMap := &core.ParameterMap{
Parameters: map[string]*core.Parameter{
"foo": {
foo: {
Var: &core.Variable{
Type: &core.LiteralType{Type: &core.LiteralType_Simple{Simple: core.SimpleType_STRING}},
},
Expand All @@ -383,7 +387,7 @@ func TestValidateSchedule_KickoffTimeBound(t *testing.T) {
request := testutils.GetLaunchPlanRequestWithDeprecatedCronSchedule("* * * * * *")
inputMap := &core.ParameterMap{
Parameters: map[string]*core.Parameter{
"foo": {
foo: {
Var: &core.Variable{
Type: &core.LiteralType{Type: &core.LiteralType_Simple{Simple: core.SimpleType_DATETIME}},
},
Expand All @@ -393,7 +397,7 @@ func TestValidateSchedule_KickoffTimeBound(t *testing.T) {
},
},
}
request.Spec.EntityMetadata.Schedule.KickoffTimeInputArg = "foo"
request.Spec.EntityMetadata.Schedule.KickoffTimeInputArg = foo

err := validateSchedule(request, inputMap)
assert.Nil(t, err)
Expand Down
17 changes: 17 additions & 0 deletions flyteadmin/pkg/manager/impl/validation/validation.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package validation

import (
"fmt"
"net/url"
"strconv"
"strings"
Expand Down Expand Up @@ -282,11 +283,27 @@ func validateParameterMap(inputMap *core.ParameterMap, fieldName string) error {
defaultValue := defaultInput.GetDefault()
if defaultValue != nil {
inputType := validators.LiteralTypeForLiteral(defaultValue)

if inputType == nil {
return errors.NewFlyteAdminErrorf(codes.InvalidArgument,
fmt.Sprintf(
"Flyte encountered an issue while determining\n"+
"the type of the default value for Parameter '%s' in '%s'.\n"+
"Registered type: [%s].\n"+
"Flyte needs to support the latest FlyteIDL to support this type.\n"+
"Suggested solution: Please update all of your Flyte images to the latest version and "+
"try again.",
name, fieldName, defaultInput.GetVar().GetType().String(),
),
)
}

if !validators.AreTypesCastable(inputType, defaultInput.GetVar().GetType()) {
return errors.NewFlyteAdminErrorf(codes.InvalidArgument,
"Type mismatch for Parameter %s in %s has type %s, expected %s", name, fieldName,
defaultInput.GetVar().GetType().String(), inputType.String())
}

if defaultInput.GetVar().GetType().GetSimple() == core.SimpleType_DATETIME {
// Make datetime specific validations
return ValidateDatetime(defaultValue)
Expand Down
38 changes: 38 additions & 0 deletions flyteadmin/pkg/manager/impl/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,44 @@ func TestValidateParameterMap(t *testing.T) {
err := validateParameterMap(&exampleMap, "some text")
assert.NoError(t, err)
})
t.Run("invalid because inputType is nil", func(t *testing.T) {
// Create a literal that will cause LiteralTypeForLiteral to return nil.
// For example, a scalar with no value.
unsupportedLiteral := &core.Literal{
Value: &core.Literal_Scalar{
Scalar: &core.Scalar{},
},
}

name := "foo"
fieldName := "test_field_name"
exampleMap := core.ParameterMap{
Parameters: map[string]*core.Parameter{
name: {
Var: &core.Variable{
// 1000 means an unsupported type
Type: &core.LiteralType{Type: &core.LiteralType_Simple{Simple: 1000}},
},
Behavior: &core.Parameter_Default{
Default: unsupportedLiteral,
},
},
},
}
err := validateParameterMap(&exampleMap, fieldName)
assert.Error(t, err)
fmt.Println(err.Error())
expectedErrMsg := fmt.Sprintf(
"Flyte encountered an issue while determining\n"+
"the type of the default value for Parameter '%s' in '%s'.\n"+
"Registered type: [%s].\n"+
"Flyte needs to support the latest FlyteIDL to support this type.\n"+
"Suggested solution: Please update all of your Flyte images to the latest version and "+
"try again.",
name, fieldName, exampleMap.Parameters[name].GetVar().GetType().String(),
)
assert.Equal(t, expectedErrMsg, err.Error())
})
}

func TestValidateToken(t *testing.T) {
Expand Down

0 comments on commit 021c606

Please sign in to comment.