Skip to content

Commit

Permalink
fix(sdk): fix upload_pipeline when no pipeline name is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
tarat44 committed Jan 31, 2023
1 parent c79d35f commit 2d66b52
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions sdk/RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
## Deprecations

## Bug fixes and other changes
* Fix upload_pipeline method on client when no name is provided

## Documentation updates
# 2.0.0-beta.11
Expand Down
5 changes: 2 additions & 3 deletions sdk/python/kfp/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1372,9 +1372,8 @@ def upload_pipeline(
``ApiPipeline`` object.
"""
if pipeline_name is None:
pipeline_name = os.path.splitext(
os.path.basename('something/file.txt'))[0]

pipeline_yaml = self._extract_pipeline_yaml(pipeline_package_path)
pipeline_name = pipeline_yaml['pipelineInfo']['name']
validate_pipeline_resource_name(pipeline_name)
response = self._upload_api.upload_pipeline(
pipeline_package_path, name=pipeline_name, description=description)
Expand Down
39 changes: 39 additions & 0 deletions sdk/python/kfp/client/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,45 @@ def test_get_kfp_healthz_should_raise_error(self, mock_get_kfp_healthz):
self.client.get_kfp_healthz(sleep_duration=0)
mock_get_kfp_healthz.assert_called()

def test_upload_pipeline_without_name(self):

@component
def return_bool(boolean: bool) -> bool:
return boolean

@pipeline(name='test-upload-without-name', description='description')
def pipeline_test_upload_without_name(boolean: bool = True):
return_bool(boolean=boolean)

with patch.object(self.client._upload_api,
'upload_pipeline') as mock_upload_pipeline:
with patch.object(self.client, '_is_ipython', return_value=False):
with tempfile.TemporaryDirectory() as tmp_path:
pipeline_test_path = os.path.join(tmp_path, 'test.yaml')
Compiler().compile(
pipeline_func=pipeline_test_upload_without_name,
package_path=pipeline_test_path)
self.client.upload_pipeline(
pipeline_package_path=pipeline_test_path,
description='description')
mock_upload_pipeline.assert_called_once_with(
pipeline_test_path,
name='test-upload-without-name',
description='description')

def test_upload_pipeline_with_name(self):
with patch.object(self.client._upload_api,
'upload_pipeline') as mock_upload_pipeline:
with patch.object(self.client, '_is_ipython', return_value=False):
self.client.upload_pipeline(
pipeline_package_path='fake.yaml',
pipeline_name='overwritten-name',
description='description')
mock_upload_pipeline.assert_called_once_with(
'fake.yaml',
name='overwritten-name',
description='description')


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

0 comments on commit 2d66b52

Please sign in to comment.