diff --git a/sdk/python/kfp/components/_components.py b/sdk/python/kfp/components/_components.py index 8a288eedef3..2aeafd2c27b 100644 --- a/sdk/python/kfp/components/_components.py +++ b/sdk/python/kfp/components/_components.py @@ -164,11 +164,15 @@ def _generate_output_file_name(port_name): def _try_get_object_by_name(obj_name): '''Locates any Python object (type, module, function, global variable) by name''' - ##Might be heavy since locate searches all Python modules - #from pydoc import locate - #return locate(obj_name) or obj_name - import builtins - return builtins.__dict__.get(obj_name, obj_name) + try: + ##Might be heavy since locate searches all Python modules + #from pydoc import locate + #return locate(obj_name) or obj_name + import builtins + return builtins.__dict__.get(obj_name, obj_name) + except: + pass + return obj_name def _make_name_unique_by_adding_index(name:str, collection, delimiter:str): @@ -355,7 +359,7 @@ def expand_argument_list(argument_list): #Reordering the inputs since in Python optional parameters must come after reuired parameters reordered_input_list = [input for input in inputs_list if not input.optional] + [input for input in inputs_list if input.optional] - input_parameters = [_dynamic.KwParameter(input_name_to_pythonic[port.name], annotation=(_try_get_object_by_name(port.type) if port.type else inspect.Parameter.empty), default=(None if port.optional else inspect.Parameter.empty)) for port in reordered_input_list] + input_parameters = [_dynamic.KwParameter(input_name_to_pythonic[port.name], annotation=(_try_get_object_by_name(str(port.type)) if port.type else inspect.Parameter.empty), default=(None if port.optional else inspect.Parameter.empty)) for port in reordered_input_list] factory_function_parameters = input_parameters #Outputs are no longer part of the task factory function signature. The paths are always generated by the system. return _dynamic.create_function_from_parameters(