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

SDK/Components - Do not crash on non-hashable objects #511

Merged
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
16 changes: 10 additions & 6 deletions sdk/python/kfp/components/_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down