Skip to content

Commit b1c55c2

Browse files
committed
Handle export task type
1 parent 687421e commit b1c55c2

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

labelbox/schema/task.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Task(DbObject):
3939
status = Field.String("status")
4040
completion_percentage = Field.Float("completion_percentage")
4141
result_url = Field.String("result_url", "result")
42+
type = Field.String("type")
4243
_user: Optional["User"] = None
4344

4445
# Relationships
@@ -100,14 +101,15 @@ def result(self) -> Union[List[Dict[str, Any]], Dict[str, Any]]:
100101
raise ValueError(f"Job failed. Errors : {self.errors}")
101102
else:
102103
result = self._fetch_remote_json()
103-
if 'createdDataRows' in result:
104-
return [{
105-
'id': data_row['id'],
106-
'external_id': data_row.get('externalId'),
107-
'row_data': data_row['rowData'],
108-
'global_key': data_row.get('globalKey'),
109-
} for data_row in result['createdDataRows']]
110-
return result
104+
if self.type == 'export-data-rows':
105+
return result
106+
107+
return [{
108+
'id': data_row['id'],
109+
'external_id': data_row.get('externalId'),
110+
'row_data': data_row['rowData'],
111+
'global_key': data_row.get('globalKey'),
112+
} for data_row in result['createdDataRows']]
111113

112114
@property
113115
def failed_data_rows(self) -> Optional[Dict[str, Any]]:
@@ -134,9 +136,13 @@ def download_result():
134136
try:
135137
return ndjson.loads(response.text)
136138
except Exception as e:
137-
raise ValueError(
138-
"Unable to parse JSON or NDJSON. Please contact support for more details. Download task.result_url manually to access the result for other tasks."
139-
)
139+
raise ValueError("Failed to parse task JSON/NDJSON result.")
140+
141+
if self.name != 'JSON Import' and self.type != 'export-data-rows':
142+
raise ValueError(
143+
"Task result is only supported for `JSON Import` and `export` tasks."
144+
" Download task.result_url manually to access the result for other tasks."
145+
)
140146

141147
if self.status != "IN_PROGRESS":
142148
return download_result()

tests/integration/annotation_import/test_model_run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def test_model_run_export_labels(model_run_with_model_run_data_rows):
117117
assert len(labels) == 3
118118

119119

120-
@pytest.mark.skip(reason="feature under development")
120+
# @pytest.mark.skip(reason="feature under development")
121121
def test_model_run_export_v2(model_run_with_model_run_data_rows,
122122
configured_project):
123123
task_name = "test_task"

0 commit comments

Comments
 (0)