fix(sdk): fix load v1 if present placeholder (#7765)

* fix load v1 if present placeholder

* add test for load v1 if present placeholder
This commit is contained in:
Connor McCarthy 2022-06-02 10:49:53 -06:00 committed by GitHub
parent d25bbc88b1
commit 0cf817364c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 4 deletions

View File

@ -841,18 +841,20 @@ class ComponentSpec(base_model.BaseModel):
input_name=utils.sanitize_input_name(
if_placeholder_values['cond']['isPresent']),
then=[
convert_str_or_dict_to_placeholder(val)
convert_str_or_dict_to_placeholder(
convert_v1_if_present_placholder_to_v2(val))
for val in if_placeholder_values_then
],
otherwise=[
convert_str_or_dict_to_placeholder(val)
convert_str_or_dict_to_placeholder(
convert_v1_if_present_placholder_to_v2(val))
for val in if_placeholder_values_else
]))
elif 'concat' in arg:
return ConcatPlaceholder(items=[
convert_str_or_dict_to_placeholder(val)
convert_str_or_dict_to_placeholder(
convert_v1_if_present_placholder_to_v2(val))
for val in arg['concat']
])
elif isinstance(arg, (ValidCommandArgTypes, dict)):

View File

@ -91,6 +91,30 @@ COMPONENT_SPEC_CONCAT_PLACEHOLDER = structures.ComponentSpec(
inputs={'input_prefix': structures.InputSpec(type='String')},
)
V1_YAML_NESTED_PLACEHOLDER = textwrap.dedent("""\
name: component_nested
implementation:
container:
args:
- concat:
- --arg1
- if:
cond:
isPresent: input_prefix
else:
- --arg2
- default
- concat:
- --arg1
- {inputValue: input_prefix}
then:
- --arg1
- {inputValue: input_prefix}
image: alpine
inputs:
- {name: input_prefix, optional: false, type: String}
""")
COMPONENT_SPEC_NESTED_PLACEHOLDER = structures.ComponentSpec(
name='component_nested',
implementation=structures.Implementation(
@ -287,6 +311,10 @@ sdkVersion: kfp-2.0.0-alpha.2
'yaml': V1_YAML_CONCAT_PLACEHOLDER,
'expected_component': COMPONENT_SPEC_CONCAT_PLACEHOLDER
},
{
'yaml': V1_YAML_NESTED_PLACEHOLDER,
'expected_component': COMPONENT_SPEC_NESTED_PLACEHOLDER
},
)
def test_component_spec_placeholder_load_from_v2_component_yaml(
self, yaml, expected_component):