Skip to content

Commit

Permalink
SDK/Components - Do not crash on non-hashable objectsApparently Pytho…
Browse files Browse the repository at this point in the history
…n's `dict.get` throws exception when it thinks that the object is not suitable for key. (kubeflow#511)
  • Loading branch information
Ark-kun authored and qimingj committed Dec 11, 2018
1 parent 8aa489a commit 5bcf10c
Showing 1 changed file with 10 additions and 6 deletions.
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

0 comments on commit 5bcf10c

Please sign in to comment.