Skip to content

Commit f3d1dbd

Browse files
author
Val Brodsky
committed
Implement global key support for move_data_rows_to_task_queue
1 parent e896c9e commit f3d1dbd

File tree

2 files changed

+46
-18
lines changed

2 files changed

+46
-18
lines changed

labelbox/schema/project.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55
from collections import namedtuple
66
from datetime import datetime, timezone
77
from pathlib import Path
8-
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Union
8+
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, TypeVar, Union, overload
99
from urllib.parse import urlparse
1010

1111
import requests
1212

1313
from labelbox import parser
1414
from labelbox import utils
15-
from labelbox.exceptions import (InvalidQueryError, LabelboxError,
16-
ProcessingWaitTimeout, ResourceConflict,
17-
ResourceNotFoundError)
15+
from labelbox.exceptions import (
16+
InvalidQueryError,
17+
LabelboxError,
18+
ProcessingWaitTimeout,
19+
ResourceConflict,
20+
)
1821
from labelbox.orm import query
1922
from labelbox.orm.db_object import DbObject, Deletable, Updateable, experimental
2023
from labelbox.orm.model import Entity, Field, Relationship
@@ -25,7 +28,7 @@
2528
from labelbox.schema.export_filters import ProjectExportFilters, validate_datetime, build_filters
2629
from labelbox.schema.export_params import ProjectExportParams
2730
from labelbox.schema.export_task import ExportTask
28-
from labelbox.schema.identifiable import DataRowIdentifiers, IdType, UniqueIds, strings_to_identifiable
31+
from labelbox.schema.identifiable import DataRowIdentifiers, strings_to_identifiable
2932
from labelbox.schema.media_type import MediaType
3033
from labelbox.schema.queue_mode import QueueMode
3134
from labelbox.schema.resource_tag import ResourceTag
@@ -1375,29 +1378,43 @@ def task_queues(self) -> List[TaskQueue]:
13751378
for field_values in task_queue_values
13761379
]
13771380

1381+
@overload
1382+
def move_data_rows_to_task_queue(self, data_row_ids: DataRowIdentifiers,
1383+
task_queue_id: str):
1384+
pass
1385+
1386+
@overload
13781387
def move_data_rows_to_task_queue(self, data_row_ids: List[str],
13791388
task_queue_id: str):
1389+
pass
1390+
1391+
def move_data_rows_to_task_queue(self, data_row_ids, task_queue_id: str):
13801392
"""
13811393
13821394
Moves data rows to the specified task queue.
13831395
13841396
Args:
1385-
data_row_ids: a list of data row ids to be moved
1397+
data_row_ids: a list of data row ids to be moved. This can be a list of strings or a DataRowIdentifiers object
1398+
DataRowIdentifier objects are lists of ids or global keys
13861399
task_queue_id: the task queue id to be moved to, or None to specify the "Done" queue
13871400
13881401
Returns:
13891402
None if successful, or a raised error on failure
13901403
13911404
"""
1405+
if isinstance(data_row_ids, list):
1406+
data_row_ids = strings_to_identifiable(data_row_ids)
1407+
13921408
method = "createBulkAddRowsToQueueTask"
13931409
query_str = """mutation AddDataRowsToTaskQueueAsyncPyApi(
13941410
$projectId: ID!
13951411
$queueId: ID
13961412
$dataRowIds: [ID!]!
1413+
$idType: IdType!
13971414
) {
13981415
project(where: { id: $projectId }) {
13991416
%s(
1400-
data: { queueId: $queueId, dataRowIds: $dataRowIds }
1417+
data: { queueId: $queueId, dataRowIds: $dataRowIds, idType: $idType }
14011418
) {
14021419
taskId
14031420
}
@@ -1409,7 +1426,8 @@ def move_data_rows_to_task_queue(self, data_row_ids: List[str],
14091426
query_str, {
14101427
"projectId": self.uid,
14111428
"queueId": task_queue_id,
1412-
"dataRowIds": data_row_ids
1429+
"dataRowIds": data_row_ids.keys,
1430+
"idType": data_row_ids.id_type,
14131431
},
14141432
timeout=180.0,
14151433
experimental=True)["project"][method]["taskId"]
Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import time
22

33
from labelbox import Project
4+
from labelbox.schema.identifiable import GlobalKeys
45

56

67
def test_get_task_queue(project: Project):
@@ -11,22 +12,15 @@ def test_get_task_queue(project: Project):
1112
assert review_queue
1213

1314

14-
def test_move_to_task(configured_batch_project_with_label: Project):
15-
project, _, data_row, label = configured_batch_project_with_label
16-
task_queues = project.task_queues()
17-
18-
review_queue = next(
19-
tq for tq in task_queues if tq.queue_type == "MANUAL_REVIEW_QUEUE")
20-
project.move_data_rows_to_task_queue([data_row.uid], review_queue.uid)
21-
15+
def _validate_moved(project, queue_name, data_row_count):
2216
timeout_seconds = 30
2317
sleep_time = 2
2418
while True:
2519
task_queues = project.task_queues()
2620
review_queue = next(
27-
tq for tq in task_queues if tq.queue_type == "MANUAL_REVIEW_QUEUE")
21+
tq for tq in task_queues if tq.queue_type == queue_name)
2822

29-
if review_queue.data_row_count == 1:
23+
if review_queue.data_row_count == data_row_count:
3024
break
3125

3226
if timeout_seconds <= 0:
@@ -35,3 +29,19 @@ def test_move_to_task(configured_batch_project_with_label: Project):
3529

3630
timeout_seconds -= sleep_time
3731
time.sleep(sleep_time)
32+
33+
34+
def test_move_to_task(configured_batch_project_with_label: Project):
35+
project, _, data_row, _ = configured_batch_project_with_label
36+
task_queues = project.task_queues()
37+
38+
review_queue = next(
39+
tq for tq in task_queues if tq.queue_type == "MANUAL_REVIEW_QUEUE")
40+
project.move_data_rows_to_task_queue([data_row.uid], review_queue.uid)
41+
_validate_moved(project, "MANUAL_REVIEW_QUEUE", 1)
42+
43+
review_queue = next(
44+
tq for tq in task_queues if tq.queue_type == "MANUAL_REWORK_QUEUE")
45+
project.move_data_rows_to_task_queue(GlobalKeys([data_row.global_key]),
46+
review_queue.uid)
47+
_validate_moved(project, "MANUAL_REWORK_QUEUE", 1)

0 commit comments

Comments
 (0)