Skip to content

Commit

Permalink
use _from_executor_fields when available
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-mccarthy committed Sep 1, 2022
1 parent 8d5716c commit 189a579
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 6 additions & 0 deletions sdk/python/kfp/components/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@ def create_artifact_instance(

artifact_cls = artifact_types._SCHEMA_TITLE_TO_TYPE.get(
schema_title) or artifact_cls or artifact_types.Artifact
if hasattr(artifact_cls, '_from_executor_fields'):
return artifact_cls._from_executor_fields(
uri=runtime_artifact.get('uri', ''),
name=runtime_artifact.get('name', ''),
metadata=runtime_artifact.get('metadata', {}),
)
return artifact_cls(
uri=runtime_artifact.get('uri', ''),
name=runtime_artifact.get('name', ''),
Expand Down
17 changes: 12 additions & 5 deletions sdk/python/kfp/components/executor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,10 +826,17 @@ class VertexDataset:
schema_title = 'google.VertexDataset'
schema_version = '0.0.0'

def __init__(self, name: str, uri: str, metadata: dict) -> None:
self.name = name
self.uri = uri
self.metadata = metadata
def __init__(self, display_name: str) -> None:
self.display_name = display_name
self.name = 'my_name'
self.uri = 'my_uri'
self.metadata = {}

@classmethod
def _from_executor_fields(cls, name: str, uri: str,
metadata: dict) -> 'VertexDataset':
print('Used _from_executor_fields to construct')
return VertexDataset(display_name=name)

@property
def path(self) -> str:
Expand Down Expand Up @@ -960,7 +967,7 @@ def test_dict_to_artifact_nonkfp_artifact(self):
},
'uri': 'gs://some-bucket/input_artifact_one'
}
# with artifact_cls
# with artifact_cls, using _from_executor_fields
self.assertIsInstance(
executor.create_artifact_instance(
runtime_artifact, artifact_cls=VertexDataset), VertexDataset)
Expand Down

0 comments on commit 189a579

Please sign in to comment.