Skip to content

Commit 9d9d257

Browse files
author
Val Brodsky
committed
PR feedback: implement create_data_row using create_data_rows_sync
1 parent b3c25ad commit 9d9d257

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

libs/labelbox/src/labelbox/schema/dataset.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,25 +140,18 @@ def create_data_row(self, items=None, **kwargs) -> "DataRow":
140140
any of the field names given in `kwargs`.
141141
ResourceCreationError: If data row creation failed on the server side.
142142
"""
143-
file_upload_thread_count = 1
144-
args = items if items is not None else kwargs
143+
invalid_argument_error = "Argument to create_data_row() must be either a dictionary, or kwargs containing `row_data` at minimum"
145144

146-
upload_items = self._separate_and_process_items([args])
147-
specs = DataRowCreateItem.build(self.uid, upload_items)
148-
task: DataUpsertTask = self._exec_upsert_data_rows(
149-
specs, file_upload_thread_count)
145+
if items is not None and len(kwargs) > 0:
146+
raise InvalidQueryError(invalid_argument_error)
150147

151-
task.wait_till_done()
148+
args = items if items is not None else kwargs
152149

153-
if task.has_errors():
154-
raise ResourceCreationError(
155-
f"Data row upload errors: {task.errors}", cause=task.uid)
156-
if task.status != "COMPLETE":
157-
raise ResourceCreationError(
158-
f"Data row upload did not complete, task status {task.status} task id {task.uid}"
159-
)
150+
file_upload_thread_count = 1
151+
completed_task = self._create_data_rows_sync(
152+
[args], file_upload_thread_count=file_upload_thread_count)
160153

161-
res = task.result
154+
res = completed_task.result
162155
if res is None or len(res) == 0:
163156
raise ResourceCreationError(
164157
f"Data row upload did not complete, task status {task.status} task id {task.uid}"
@@ -190,8 +183,17 @@ def create_data_rows_sync(
190183
a DataRow.
191184
ValueError: When the upload parameters are invalid
192185
"""
193-
max_data_rows_supported = 1000
194186
max_attachments_per_data_row = 5
187+
self._create_data_rows_sync(
188+
items, file_upload_thread_count=file_upload_thread_count)
189+
190+
return None # Return None if no exception is raised
191+
192+
def _create_data_rows_sync(self,
193+
items,
194+
file_upload_thread_count=FILE_UPLOAD_THREAD_COUNT
195+
) -> "DataUpsertTask":
196+
max_data_rows_supported = 1000
195197
if len(items) > max_data_rows_supported:
196198
raise ValueError(
197199
f"Dataset.create_data_rows_sync() supports a max of {max_data_rows_supported} data rows."
@@ -215,7 +217,7 @@ def create_data_rows_sync(
215217
f"Data row upload did not complete, task status {task.status} task id {task.uid}"
216218
)
217219

218-
return None
220+
return task
219221

220222
def create_data_rows(self,
221223
items,

0 commit comments

Comments
 (0)