Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flytepropeller][compiler] Error Handling when Type is not found #5612

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading