Skip to content

Commit a434cb7

Browse files
committed
Fix infinite recursion problem on artifact_type custom_path property.
Signed-off-by: agoins <[email protected]>
1 parent d5b3bde commit a434cb7

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

sdk/python/kfp/dsl/executor.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ def assign_input_and_output_artifacts(self) -> None:
102102
self.func,
103103
)
104104
self.output_artifacts[name] = output_artifact
105-
#todo: I think this is where we are creating artifact files in local container storage.
106105
makedirs_recursively(output_artifact.path)
107106

108107
def make_artifact(
@@ -305,7 +304,6 @@ def write_executor_output(self,
305304
write_file = cluster_spec['task']['type'] in CHIEF_NODE_LABELS
306305

307306
if write_file:
308-
#todo. this method is called by execute(), and here is where it is dumping the artifact output locally.
309307
makedirs_recursively(self.executor_output_path)
310308
with open(self.executor_output_path, 'w') as f:
311309
f.write(json.dumps(self.excutor_output))

sdk/python/kfp/dsl/executor_test.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ def test_artifact_output1(self):
616616
"schemaTitle": "system.Artifact"
617617
},
618618
"uri": "gs://some-bucket/output",
619-
'custom_path':""
619+
"custom_path": ""
620620
}
621621
]
622622
}
@@ -648,7 +648,9 @@ def test_func(first: str, second: str, output: Output[Artifact]) -> str:
648648
'name':
649649
'projects/123/locations/us-central1/metadataStores/default/artifacts/123',
650650
'uri':
651-
'gs://some-bucket/output'
651+
'gs://some-bucket/output',
652+
'custom_path':
653+
''
652654
}]
653655
}
654656
},
@@ -1061,7 +1063,7 @@ def test_func(
10611063
'',
10621064
'uri':
10631065
'gs://mlpipeline/v2/artifacts/my-test-pipeline-beta/b2b0cdee-b15c-48ff-b8bc-a394ae46c854/train/model',
1064-
'custom_path':
1066+
"custom_path":
10651067
'',
10661068
'metadata': {
10671069
'accuracy': 0.9

sdk/python/kfp/dsl/types/artifact_types.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,12 @@ def __init__(self,
7878
name: Optional[str] = None,
7979
uri: Optional[str] = None,
8080
metadata: Optional[Dict] = None) -> None:
81-
"""Initializes the Artifact with the given name, URI and metadata."""
81+
"""Initializes the Artifact with the given name, URI, metadata, and blank custom path."""
8282
self.uri = uri or ''
8383
self.name = name or ''
8484
self.metadata = metadata or {}
85-
self.custom_path = None
85+
self._custom_path = ''
8686

87-
#todo: this is designed to return custom path if set, and otherwise return local container storage path.s
8887
@property
8988
def path(self) -> str:
9089
return self._get_path()
@@ -93,10 +92,9 @@ def path(self) -> str:
9392
def path(self, path: str) -> None:
9493
self._set_custom_path(path)
9594

96-
#todo: here the path property returns the custom path if set --> otherwise, returns the regular path/
9795
def _get_path(self) -> Optional[str]:
98-
if self.custom_path is not None:
99-
return self.custom_path
96+
if self.custom_path is not '':
97+
return self._get_custom_path()
10098
if self.uri.startswith(RemotePrefix.GCS.value):
10199
return _GCS_LOCAL_MOUNT_PREFIX + self.uri[len(RemotePrefix.GCS.value
102100
):]
@@ -115,23 +113,19 @@ def _get_path(self) -> Optional[str]:
115113

116114
@property
117115
def custom_path(self) -> str:
118-
return self._get_custom_path()
116+
return self._custom_path
119117

120-
def _get_custom_path(self) -> Optional[str]:
121-
if self.custom_path is not None:
122-
return self.custom_path
123-
return None
118+
def _get_custom_path(self) -> str:
119+
return self._custom_path
124120

125-
#todo: this is the internal function to set the path.
126121
def _set_path(self, path: str) -> None:
127122
self.uri = convert_local_path_to_remote_path(path)
128123

129-
#todo: what differentiates this from setting the path regularly?
130-
def _set_custom_path(self, custom_path: str) -> None:
131-
self.custom_path = custom_path
124+
def _set_custom_path(self, value: str) -> None:
125+
self._custom_path = value
132126

133127
@custom_path.setter
134-
def custom_path(self, value):
128+
def custom_path(self, value: str):
135129
self._custom_path = value
136130

137131

0 commit comments

Comments
 (0)