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 1 commit
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
16 changes: 16 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,26 @@ 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 Propeller encountered an issue while determining\n"+
"the type of the default value for Parameter '%s' in '%s'.\n"+
"Registered type from FlyteKit: [%s].\n"+
Future-Outlier marked this conversation as resolved.
Show resolved Hide resolved
"FlytePropeller needs to support latest FlyteIDL to support this type.\n"+
"Suggested solution: Please update your Flyte Propeller image 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
32 changes: 32 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,38 @@ 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{},
},
}

exampleMap := core.ParameterMap{
Parameters: map[string]*core.Parameter{
"foo": {
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, "test_field_name")
assert.Error(t, err)
fmt.Println(err.Error())
expectedErrMsg := "Flyte Propeller encountered an issue while determining\n" +
"the type of the default value for Parameter 'foo' in 'test_field_name'.\n" +
"Registered type from FlyteKit: [simple:1000].\n" +
"FlytePropeller needs to support latest FlyteIDL to support this type.\n" +
"Suggested solution: Please update your Flyte Propeller image to the latest version and try again."
assert.Equal(t, expectedErrMsg, err.Error())
})
}

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