|
10 | 10 | import ndjson |
11 | 11 | import requests |
12 | 12 | from pydantic import BaseModel, validator |
| 13 | +from requests.api import request |
13 | 14 | from typing_extensions import Literal |
14 | 15 | from typing import (Any, List, Optional, BinaryIO, Dict, Iterable, Tuple, Union, |
15 | 16 | Type, Set) |
@@ -115,58 +116,77 @@ class BulkImportRequest(DbObject): |
115 | 116 | created_by = Relationship.ToOne("User", False, "created_by") |
116 | 117 |
|
117 | 118 | @property |
118 | | - def inputs(self) -> Optional[List[Dict[str, str]]]: |
| 119 | + def inputs(self) -> List[Dict[str, Any]]: |
119 | 120 | """ |
120 | 121 | Inputs for each individual annotation uploaded. |
121 | 122 | This should match the ndjson annotations that you have uploaded. |
122 | 123 | |
123 | 124 | Returns: |
124 | | - Uploaded ndjsons. |
| 125 | + Uploaded ndjson. |
125 | 126 |
|
126 | 127 | * This information will expire after 24 hours. |
127 | 128 | """ |
128 | 129 | return self._fetch_remote_ndjson(self.input_file_url) |
129 | 130 |
|
130 | 131 | @property |
131 | | - def errors(self) -> Optional[List[Dict[str, str]]]: |
| 132 | + def errors(self) -> List[Dict[str, Any]]: |
132 | 133 | """ |
133 | | - Errors for each individual annotation uploaded. |
| 134 | + Errors for each individual annotation uploaded. This is a subset of statuses |
134 | 135 |
|
135 | 136 | 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. |
| 137 | + List of dicts containing error messages. Empty list means there were no errors |
| 138 | + See `BulkImportRequest.statuses` for more details. |
138 | 139 |
|
139 | 140 | * This information will expire after 24 hours. |
140 | 141 | """ |
| 142 | + self.wait_until_done() |
141 | 143 | return self._fetch_remote_ndjson(self.error_file_url) |
142 | 144 |
|
143 | 145 | @property |
144 | | - def statuses(self) -> Optional[List[Dict[str, str]]]: |
| 146 | + def statuses(self) -> List[Dict[str, Any]]: |
145 | 147 | """ |
146 | 148 | Status for each individual annotation uploaded. |
147 | 149 |
|
148 | 150 | Returns: |
149 | | - A status for each annotation if the upload is done running and was successful. Otherwise it returns None. |
| 151 | + A status for each annotation if the upload is done running. |
| 152 | + See below table for more details |
| 153 | + |
| 154 | + .. list-table:: |
| 155 | + :widths: 15 150 |
| 156 | + :header-rows: 1 |
| 157 | +
|
| 158 | + * - Field |
| 159 | + - Description |
| 160 | + * - uuid |
| 161 | + - Specifies the annotation for the status row. |
| 162 | + * - dataRow |
| 163 | + - JSON object containing the Labelbox data row ID for the annotation. |
| 164 | + * - status |
| 165 | + - Indicates SUCCESS or FAILURE. |
| 166 | + * - errors |
| 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. |
150 | 168 |
|
151 | 169 | * This information will expire after 24 hours. |
152 | 170 | """ |
| 171 | + self.wait_until_done() |
153 | 172 | return self._fetch_remote_ndjson(self.status_file_url) |
154 | 173 |
|
155 | 174 | @functools.lru_cache() |
156 | | - def _fetch_remote_ndjson( |
157 | | - self, url: Optional[str]) -> Optional[List[Dict[str, str]]]: |
| 175 | + def _fetch_remote_ndjson(self, url: str) -> List[Dict[str, Any]]: |
158 | 176 | """ |
159 | 177 | Fetches the remote ndjson file and caches the results. |
160 | 178 |
|
161 | 179 | Args: |
162 | | - url (str): either the input_file_url, error_file_url, status_file_url, or None |
163 | | - urls are None when the file is unavailable. |
| 180 | + url (str): Can be any url pointing to an ndjson file. |
164 | 181 | Returns: |
165 | | - None if the url is None or the ndjson as a list of dicts. |
| 182 | + ndjson as a list of dicts. |
166 | 183 | """ |
167 | | - if url is not None: |
168 | | - return ndjson.loads(requests.get(url).text) |
169 | | - 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) |
170 | 190 |
|
171 | 191 | def refresh(self) -> None: |
172 | 192 | """Synchronizes values of all fields with the database. |
|
0 commit comments