Skip to content

Commit 95b56ca

Browse files
Merge pull request #854 from Labelbox/kkim/fix-gk-error-msg
Fix wording for assign_global_keys_to_data_rows error message
2 parents 3c7128e + b23a349 commit 95b56ca

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

labelbox/client.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,8 +1115,11 @@ def _format_failed_rows(rows: Dict[str, str],
11151115
sanitized=False))
11161116
# Failed assignments
11171117
errors.extend(
1118-
_format_failed_rows(rows=res['invalidGlobalKeyAssignments'],
1119-
error_msg="Invalid global key"))
1118+
_format_failed_rows(
1119+
rows=res['invalidGlobalKeyAssignments'],
1120+
error_msg=
1121+
"Invalid assignment. Either DataRow does not exist, or globalKey is invalid"
1122+
))
11201123
errors.extend(
11211124
_format_failed_rows(rows=res['accessDeniedAssignments'],
11221125
error_msg="Access denied to Data Row"))
@@ -1271,13 +1274,13 @@ def clear_global_keys(
12711274
'Errors' contains a list of global_keys correspond to the data rows that could not be
12721275
modified, accessed by the user, or not found.
12731276
Examples:
1274-
>>> job_result = client.get_data_row_ids_for_global_keys(["key1","key2"])
1277+
>>> job_result = client.clear_global_keys(["key1","key2","notfoundkey"])
12751278
>>> print(job_result['status'])
12761279
Partial Success
12771280
>>> print(job_result['results'])
1278-
['cl7tv9wry00hlka6gai588ozv', 'cl7tv9wxg00hpka6gf8sh81bj']
1281+
['key1', 'key2']
12791282
>>> print(job_result['errors'])
1280-
[{'global_key': 'asdf', 'error': 'Data Row not found'}]
1283+
[{'global_key': 'notfoundkey', 'error': 'Failed to find data row matching provided global key'}]
12811284
"""
12821285

12831286
def _format_failed_rows(rows: List[str],

tests/integration/test_global_keys.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def test_assign_same_global_keys_to_data_rows(client, dataset, image_url):
7575
assert len(res['errors']) == 1
7676
assert res['errors'][0]['data_row_id'] == dr_2.uid
7777
assert res['errors'][0]['global_key'] == gk_1
78-
assert res['errors'][0]['error'] == "Invalid global key"
78+
assert res['errors'][0][
79+
'error'] == "Invalid assignment. Either DataRow does not exist, or globalKey is invalid"
7980

8081

8182
def test_global_key_sanitization(dataset, image_url):
@@ -111,7 +112,8 @@ def test_long_global_key_validation(client, dataset, image_url):
111112
assert res['results'][0]['global_key'] == gk_1
112113
assert res['errors'][0]['data_row_id'] == dr_2.uid
113114
assert res['errors'][0]['global_key'] == gk_2
114-
assert res['errors'][0]['error'] == 'Invalid global key'
115+
assert res['errors'][0][
116+
'error'] == 'Invalid assignment. Either DataRow does not exist, or globalKey is invalid'
115117

116118

117119
def test_global_key_with_whitespaces_validation(client, dataset, image_url):
@@ -143,8 +145,11 @@ def test_global_key_with_whitespaces_validation(client, dataset, image_url):
143145
assign_errors_msgs = set([e['error'] for e in res['errors']])
144146
assert assign_errors_ids == set([dr_1.uid, dr_2.uid, dr_3.uid])
145147
assert assign_errors_gks == set([gk_1, gk_2, gk_3])
146-
assert assign_errors_msgs == set(
147-
['Invalid global key', 'Invalid global key', 'Invalid global key'])
148+
assert assign_errors_msgs == set([
149+
'Invalid assignment. Either DataRow does not exist, or globalKey is invalid',
150+
'Invalid assignment. Either DataRow does not exist, or globalKey is invalid',
151+
'Invalid assignment. Either DataRow does not exist, or globalKey is invalid'
152+
])
148153

149154

150155
@pytest.mark.skip(reason='get_data_rows_for_global_keys not included in '

0 commit comments

Comments
 (0)