Skip to content

Commit

Permalink
fix(sdk): permit empty local execution outputs #localexecution (#10338)
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-mccarthy authored Jan 5, 2024
1 parent 8a5a17e commit 64d46df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 6 additions & 4 deletions sdk/python/kfp/local/executor_output_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ def cast_protobuf_numbers(
struct_pb2.Value to a dict/json, int will be upcast to float, even
if the component output specifies int.
"""
output_parameter_types = [
int_output_keys = [
output_param_name
for output_param_name, parameter_spec in output_parameter_types.items()
if parameter_spec.parameter_type ==
pipeline_spec_pb2.ParameterType.ParameterTypeEnum.NUMBER_INTEGER
]
for float_output_key in output_parameter_types:
output_parameters[float_output_key] = int(
output_parameters[float_output_key])
for int_output_key in int_output_keys:
# avoid KeyError when the user never writes to the dsl.OutputPath
if int_output_key in output_parameters:
output_parameters[int_output_key] = int(
output_parameters[int_output_key])
return output_parameters


Expand Down
13 changes: 13 additions & 0 deletions sdk/python/kfp/local/subprocess_task_handler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,19 @@ def my_comp(out_param: dsl.OutputPath(str),) -> int:
self.assertEqual(task.outputs['out_param'], 'HelloHello')
self.assertEqual(task.outputs['Output'], 1)

def test_outputpath_result_not_written(self):
local.init(runner=local.SubprocessRunner(use_venv=True))

# use dsl.OutputPath(int) for more thorough testing
# want to ensure that the code that converts protobuf number to
# Python int permits unwritten outputs
@dsl.component
def my_comp(out_param: dsl.OutputPath(int)):
pass

task = my_comp()
self.assertEmpty(task.outputs)


if __name__ == '__main__':
unittest.main()

0 comments on commit 64d46df

Please sign in to comment.