chore (sdk.v2): Error out on using InputPath placeholder for artifacts require importer. (#4929)

* throw error on importer-inputpath combination

* address review comments
This commit is contained in:
Chen Sun 2020-12-22 17:44:27 -08:00 committed by GitHub
parent cd6580cd00
commit a347765630
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 2 deletions

View File

@ -289,8 +289,7 @@ class CompilerTest(unittest.TestCase):
component_op(value=value)
with self.assertRaisesRegex(
TypeError,
' type "Float" cannot be paired with InputUriPlaceholder.'):
TypeError, ' type "Float" cannot be paired with InputUriPlaceholder.'):
compiler.Compiler().compile(
pipeline_func=my_pipeline,
pipeline_root='dummy',
@ -351,6 +350,7 @@ class CompilerTest(unittest.TestCase):
""")
def test_compile_pipeline_with_invalid_name_should_raise_error(self):
def my_pipeline():
pass
@ -363,6 +363,52 @@ class CompilerTest(unittest.TestCase):
pipeline_root='dummy',
output_path='output.json')
def test_compile_pipeline_with_importer_on_inputpath_should_raise_error(self):
# YAML componet authoring
component_op = components.load_component_from_text("""
name: compoent with misused placeholder
inputs:
- {name: model, type: Model}
implementation:
container:
image: dummy
args:
- {inputPath: model}
""")
@dsl.pipeline(name='my-component')
def my_pipeline(model):
component_op(model=model)
with self.assertRaisesRegex(
TypeError,
'Input "model" with type "Model" is not connected to any upstream '
'output. However it is used with InputPathPlaceholder.'):
compiler.Compiler().compile(
pipeline_func=my_pipeline,
pipeline_root='dummy',
output_path='output.json')
# Python function based component authoring
def my_component(datasets: components.InputPath('Datasets')):
pass
component_op = components.create_component_from_func(my_component)
@dsl.pipeline(name='my-component')
def my_pipeline(datasets):
component_op(datasets=datasets)
with self.assertRaisesRegex(
TypeError,
'Input "datasets" with type "Datasets" is not connected to any upstream '
'output. However it is used with InputPathPlaceholder.'):
compiler.Compiler().compile(
pipeline_func=my_pipeline,
pipeline_root='dummy',
output_path='output.json')
if __name__ == '__main__':
unittest.main()

View File

@ -147,6 +147,15 @@ def create_container_op_from_component_and_arguments(
raise TypeError(
'Input "{}" with type "{}" cannot be paired with InputPathPlaceholder.'
.format(input_key, inputs_dict[input_key].type))
elif input_key in importer_spec:
raise TypeError(
'Input "{}" with type "{}" is not connected to any upstream output. '
'However it is used with InputPathPlaceholder. '
'If you want to import an existing artifact using a system-connected '
'importer node, use InputUriPlaceholder instead. '
'Or if you just want to pass a string parameter, use string type and '
'InputValuePlaceholder instead.'
.format(input_key, inputs_dict[input_key].type))
else:
return "{{{{$.inputs.artifacts['{}'].path}}}}".format(input_key)