From d8f351604e540975f420fab76d36646ec3d2bcee Mon Sep 17 00:00:00 2001 From: Kevin Kim Date: Tue, 24 Jan 2023 20:17:19 -0800 Subject: [PATCH 1/4] Fix wording for assign_global_keys_to_data_rows error message --- labelbox/client.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/labelbox/client.py b/labelbox/client.py index 4d46a5024..7bb9e16ac 100644 --- a/labelbox/client.py +++ b/labelbox/client.py @@ -1114,8 +1114,9 @@ def _format_failed_rows(rows: Dict[str, str], sanitized=False)) # Failed assignments errors.extend( - _format_failed_rows(rows=res['invalidGlobalKeyAssignments'], - error_msg="Invalid global key")) + _format_failed_rows( + rows=res['invalidGlobalKeyAssignments'], + error_msg="Invalid Data Row or invalid global key")) errors.extend( _format_failed_rows(rows=res['accessDeniedAssignments'], error_msg="Access denied to Data Row")) @@ -1270,13 +1271,13 @@ def clear_global_keys( 'Errors' contains a list of global_keys correspond to the data rows that could not be modified, accessed by the user, or not found. Examples: - >>> job_result = client.get_data_row_ids_for_global_keys(["key1","key2"]) + >>> job_result = client.clear_global_keys(["key1","key2","notfoundkey"]) >>> print(job_result['status']) Partial Success >>> print(job_result['results']) - ['cl7tv9wry00hlka6gai588ozv', 'cl7tv9wxg00hpka6gf8sh81bj'] + ['key1', 'key2'] >>> print(job_result['errors']) - [{'global_key': 'asdf', 'error': 'Data Row not found'}] + [{'global_key': 'notfoundkey', 'error': 'Failed to find data row matching provided global key'}] """ def _format_failed_rows(rows: List[str], From 10bad16d9b332aeaa55320ac3ee943c464133360 Mon Sep 17 00:00:00 2001 From: Kevin Kim Date: Tue, 24 Jan 2023 22:34:20 -0800 Subject: [PATCH 2/4] yapf --- tests/integration/test_global_keys.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_global_keys.py b/tests/integration/test_global_keys.py index 078356a9c..3eb641fa8 100644 --- a/tests/integration/test_global_keys.py +++ b/tests/integration/test_global_keys.py @@ -75,7 +75,7 @@ def test_assign_same_global_keys_to_data_rows(client, dataset, image_url): assert len(res['errors']) == 1 assert res['errors'][0]['data_row_id'] == dr_2.uid assert res['errors'][0]['global_key'] == gk_1 - assert res['errors'][0]['error'] == "Invalid global key" + assert res['errors'][0]['error'] == "Invalid Data Row or invalid global key" def test_global_key_sanitization(dataset, image_url): @@ -111,7 +111,7 @@ def test_long_global_key_validation(client, dataset, image_url): assert res['results'][0]['global_key'] == gk_1 assert res['errors'][0]['data_row_id'] == dr_2.uid assert res['errors'][0]['global_key'] == gk_2 - assert res['errors'][0]['error'] == 'Invalid global key' + assert res['errors'][0]['error'] == 'Invalid Data Row or invalid global key' def test_global_key_with_whitespaces_validation(client, dataset, image_url): @@ -143,8 +143,11 @@ def test_global_key_with_whitespaces_validation(client, dataset, image_url): assign_errors_msgs = set([e['error'] for e in res['errors']]) assert assign_errors_ids == set([dr_1.uid, dr_2.uid, dr_3.uid]) assert assign_errors_gks == set([gk_1, gk_2, gk_3]) - assert assign_errors_msgs == set( - ['Invalid global key', 'Invalid global key', 'Invalid global key']) + assert assign_errors_msgs == set([ + 'Invalid Data Row or invalid global key', + 'Invalid Data Row or invalid global key', + 'Invalid Data Row or invalid global key' + ]) @pytest.mark.skip(reason='get_data_rows_for_global_keys not included in ' From 96fd24e015bfc2655e0281bfc28d30cbc96a8ace Mon Sep 17 00:00:00 2001 From: Kevin Kim Date: Wed, 25 Jan 2023 12:12:49 -0800 Subject: [PATCH 3/4] Modify error message to be clearer --- labelbox/client.py | 4 +++- tests/integration/test_global_keys.py | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/labelbox/client.py b/labelbox/client.py index 7bb9e16ac..e5e10db7c 100644 --- a/labelbox/client.py +++ b/labelbox/client.py @@ -1116,7 +1116,9 @@ def _format_failed_rows(rows: Dict[str, str], errors.extend( _format_failed_rows( rows=res['invalidGlobalKeyAssignments'], - error_msg="Invalid Data Row or invalid global key")) + error_msg= + "Invalid assignment. Either DataRow does not exist, or globalKey is invalid" + )) errors.extend( _format_failed_rows(rows=res['accessDeniedAssignments'], error_msg="Access denied to Data Row")) diff --git a/tests/integration/test_global_keys.py b/tests/integration/test_global_keys.py index 3eb641fa8..c8619b77d 100644 --- a/tests/integration/test_global_keys.py +++ b/tests/integration/test_global_keys.py @@ -75,7 +75,8 @@ def test_assign_same_global_keys_to_data_rows(client, dataset, image_url): assert len(res['errors']) == 1 assert res['errors'][0]['data_row_id'] == dr_2.uid assert res['errors'][0]['global_key'] == gk_1 - assert res['errors'][0]['error'] == "Invalid Data Row or invalid global key" + assert res['errors'][0][ + 'error'] == "Invalid assignment. Either DataRow does not exist, or globalKey is invalid" def test_global_key_sanitization(dataset, image_url): @@ -144,9 +145,9 @@ def test_global_key_with_whitespaces_validation(client, dataset, image_url): assert assign_errors_ids == set([dr_1.uid, dr_2.uid, dr_3.uid]) assert assign_errors_gks == set([gk_1, gk_2, gk_3]) assert assign_errors_msgs == set([ - 'Invalid Data Row or invalid global key', - 'Invalid Data Row or invalid global key', - 'Invalid Data Row or invalid global key' + 'Invalid assignment. Either DataRow does not exist, or globalKey is invalid', + 'Invalid assignment. Either DataRow does not exist, or globalKey is invalid', + 'Invalid assignment. Either DataRow does not exist, or globalKey is invalid' ]) From b23a3494089c5706e1f40b4616634c01a8b15442 Mon Sep 17 00:00:00 2001 From: Kevin Kim Date: Wed, 25 Jan 2023 19:40:25 -0800 Subject: [PATCH 4/4] Fix tests --- tests/integration/test_global_keys.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_global_keys.py b/tests/integration/test_global_keys.py index c8619b77d..e3fff7b80 100644 --- a/tests/integration/test_global_keys.py +++ b/tests/integration/test_global_keys.py @@ -112,7 +112,8 @@ def test_long_global_key_validation(client, dataset, image_url): assert res['results'][0]['global_key'] == gk_1 assert res['errors'][0]['data_row_id'] == dr_2.uid assert res['errors'][0]['global_key'] == gk_2 - assert res['errors'][0]['error'] == 'Invalid Data Row or invalid global key' + assert res['errors'][0][ + 'error'] == 'Invalid assignment. Either DataRow does not exist, or globalKey is invalid' def test_global_key_with_whitespaces_validation(client, dataset, image_url):