Skip to content

Commit 01239f6

Browse files
author
Matt Sokoloff
committed
bulk_import_uploads errors and statuses can't be None
1 parent 8e2b4cc commit 01239f6

File tree

2 files changed

+33
-32
lines changed

2 files changed

+33
-32
lines changed

labelbox/schema/bulk_import_request.py

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import ndjson
1111
import requests
1212
from pydantic import BaseModel, validator
13+
from requests.api import request
1314
from typing_extensions import Literal
1415
from typing import (Any, List, Optional, BinaryIO, Dict, Iterable, Tuple, Union,
1516
Type, Set)
@@ -115,28 +116,41 @@ class BulkImportRequest(DbObject):
115116
created_by = Relationship.ToOne("User", False, "created_by")
116117

117118
@property
118-
def inputs(self) -> Optional[List[Dict[str, str]]]:
119+
def inputs(self) -> List[Dict[str, Any]]:
119120
"""
120121
Inputs for each individual annotation uploaded.
121122
This should match the ndjson annotations that you have uploaded.
122123
123124
Returns:
124-
Uploaded ndjsons.
125+
Uploaded ndjson.
125126
126127
* This information will expire after 24 hours.
127128
"""
128129
return self._fetch_remote_ndjson(self.input_file_url)
129130

130131
@property
131-
def errors(self) -> Optional[List[Dict[str, str]]]:
132+
def errors(self) -> List[Dict[str, Any]]:
132133
"""
133-
Errors for each individual annotation uploaded.
134+
Errors for each individual annotation uploaded. This is a subset of statuses
134135
135136
Returns:
136-
Empty list if there are no errors and None if the update is still running.
137-
If there are errors, and the job has completed then a list of dicts containing the error messages will be returned.
138-
See below table for detailed response fields.
137+
List of dicts containing error messages. Empty list means there were no errors
138+
See `BulkImportRequest.statuses` for more details.
139139
140+
* This information will expire after 24 hours.
141+
"""
142+
self.wait_until_done()
143+
return self._fetch_remote_ndjson(self.error_file_url)
144+
145+
@property
146+
def statuses(self) -> List[Dict[str, Any]]:
147+
"""
148+
Status for each individual annotation uploaded.
149+
150+
Returns:
151+
A status for each annotation if the upload is done running.
152+
See below table for more details
153+
140154
.. list-table::
141155
:widths: 15 150
142156
:header-rows: 1
@@ -150,39 +164,29 @@ def errors(self) -> Optional[List[Dict[str, str]]]:
150164
* - status
151165
- Indicates SUCCESS or FAILURE.
152166
* - errors
153-
- An array of error messages included when status is FAILURE. Each error has a name, message and optional (can be null) additional_info.
154-
155-
* This information will expire after 24 hours.
156-
"""
157-
return self._fetch_remote_ndjson(self.error_file_url)
158-
159-
@property
160-
def statuses(self) -> Optional[List[Dict[str, str]]]:
161-
"""
162-
Status for each individual annotation uploaded.
163-
164-
Returns:
165-
A status for each annotation if the upload is done running and was successful. Otherwise it returns None.
167+
- An array of error messages included when status is FAILURE. Each error has a name, message and optional (key might not exist) additional_info.
166168
167169
* This information will expire after 24 hours.
168170
"""
171+
self.wait_until_done()
169172
return self._fetch_remote_ndjson(self.status_file_url)
170173

171174
@functools.lru_cache()
172-
def _fetch_remote_ndjson(
173-
self, url: Optional[str]) -> Optional[List[Dict[str, str]]]:
175+
def _fetch_remote_ndjson(self, url: str) -> List[Dict[str, Any]]:
174176
"""
175177
Fetches the remote ndjson file and caches the results.
176178
177179
Args:
178-
url (str): either the input_file_url, error_file_url, status_file_url, or None
179-
urls are None when the file is unavailable.
180+
url (str): Can be any url pointing to an ndjson file.
180181
Returns:
181-
None if the url is None or the ndjson as a list of dicts.
182+
ndjson as a list of dicts.
182183
"""
183-
if url is not None:
184-
return ndjson.loads(requests.get(url).text)
185-
return None
184+
if url is None:
185+
raise ValueError("Must provide valid ndjson url. Found `None`")
186+
187+
response = requests.get(url)
188+
response.raise_for_status()
189+
return ndjson.loads(response.text)
186190

187191
def refresh(self) -> None:
188192
"""Synchronizes values of all fields with the database.

tests/integration/bulk_import/test_bulk_import_request.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,11 @@ def test_wait_till_done(rectangle_inference, configured_project):
130130
annotations=url,
131131
validate=False)
132132

133-
assert bulk_import_request.errors is None
134-
assert bulk_import_request.statuses is None
135133
assert len(bulk_import_request.inputs) == 1
136-
137134
bulk_import_request.wait_until_done()
138135
assert bulk_import_request.state == BulkImportRequestState.FINISHED
139136

140-
#Check that the status files are being returned as expected
137+
# Check that the status files are being returned as expected
141138
assert len(bulk_import_request.errors) == 0
142139
assert len(bulk_import_request.inputs) == 1
143140
assert bulk_import_request.inputs[0]['uuid'] == rectangle_inference['uuid']

0 commit comments

Comments
 (0)