Skip to content

Commit 3a95890

Browse files
author
Matt Sokoloff
committed
refresh url before downloading
1 parent 4882e67 commit 3a95890

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

labelbox/schema/task.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ def errors(self) -> Optional[Dict[str, Any]]:
9494
elif self.status == "COMPLETE":
9595
return self.failed_data_rows
9696
elif self.type == "export-data-rows":
97+
self.wait_till_done(timeout_seconds=600)
9798
if self.errors_url:
98-
return self._fetch_remote_json(url=self.errors_url)
99+
return self._fetch_remote_json(remote_json_field='errors_url')
99100
elif self.type == "add-data-rows-to-batch" or self.type == "send-to-task-queue":
100101
if self.status == "FAILED":
101102
# for these tasks, the error is embedded in the result itself
@@ -131,14 +132,14 @@ def failed_data_rows(self) -> Optional[Dict[str, Any]]:
131132
return None
132133

133134
@lru_cache()
134-
def _fetch_remote_json(self, url: Optional[str] = None) -> Dict[str, Any]:
135+
def _fetch_remote_json(self,
136+
remote_json_field: Optional[str] = None
137+
) -> Dict[str, Any]:
135138
""" Function for fetching and caching the result data.
136139
"""
137-
if url is None:
138-
# for backwards compatability
139-
url = self.result_url
140140

141-
def download_result(url, format: str):
141+
def download_result(remote_json_field: Optional[str], format: str):
142+
url = getattr(self, remote_json_field or 'result_url')
142143
response = requests.get(url)
143144
response.raise_for_status()
144145
if format == 'json':
@@ -161,14 +162,14 @@ def download_result(url, format: str):
161162
)
162163

163164
if self.status != "IN_PROGRESS":
164-
return download_result(url, format)
165+
return download_result(remote_json_field, format)
165166
else:
166167
self.wait_till_done(timeout_seconds=600)
167168
if self.status == "IN_PROGRESS":
168169
raise ValueError(
169170
"Job status still in `IN_PROGRESS`. The result is not available. Call task.wait_till_done() with a larger timeout or contact support."
170171
)
171-
return download_result(url, format)
172+
return download_result(remote_json_field, format)
172173

173174
@staticmethod
174175
def get_task(client, task_id):

0 commit comments

Comments
 (0)