Skip to content

Commit 674dbd0

Browse files
rllinrllin
authored andcommitted
Revert "[BACKEND-946] [BACKEND-947] [BACKEND-948] pass thru errors, retry, catch bad annotation types" (#54)
* Revert "update version and changelog" This reverts commit 1cf98a3. * Revert "ignore missing improrts" This reverts commit 805d97f. * Revert "retry" This reverts commit 3300f77. * Revert "catchall for other errors" This reverts commit 96e1c76. * Revert "print 400s" This reverts commit 4956bb5. * Revert "loosen requirements + catch actual error for reraise" This reverts commit 8bf8e4d. * Revert "catch actual errors" This reverts commit a083993. * Revert "Update client.py" This reverts commit c656f3c. * Revert "yapf" This reverts commit 8daeaff. * Revert "update labeling frontend test to work with any project even if it has more than the default editors" This reverts commit 8d1d017. * Revert "print response when fail" This reverts commit d2a0909. * Revert "catch bad inputs" This reverts commit 621edef.
1 parent 1cf98a3 commit 674dbd0

File tree

8 files changed

+12
-67
lines changed

8 files changed

+12
-67
lines changed

CHANGELOG.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
# Changelog
22

3-
## Version 2.4.5 (2020-08-04)
4-
### Added
5-
* retry capabilities for common flaky API failures
6-
* protection against improper types passed into `Project.upload_anntations`
7-
* pass thru API error messages when possible
8-
93
## Version 2.4.3 (2020-08-04)
104

115
### Added

labelbox/client.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import os
66
from typing import Tuple
77

8-
from google.api_core import retry
98
import requests
109
import requests.exceptions
1110

@@ -61,8 +60,6 @@ def __init__(self,
6160
'Authorization': 'Bearer %s' % api_key
6261
}
6362

64-
@retry.Retry(predicate=retry.if_exception_type(
65-
labelbox.exceptions.InternalServerError))
6663
def execute(self, query, params=None, timeout=10.0):
6764
""" Sends a request to the server for the execution of the
6865
given query. Checks the response for errors and wraps errors
@@ -124,15 +121,12 @@ def convert_value(value):
124121
"Unknown error during Client.query(): " + str(e), e)
125122

126123
try:
127-
r_json = response.json()
124+
response = response.json()
128125
except:
129-
error_502 = '502 Bad Gateway'
130-
if error_502 in response.text:
131-
raise labelbox.exceptions.InternalServerError(error_502)
132126
raise labelbox.exceptions.LabelboxError(
133127
"Failed to parse response as JSON: %s" % response.text)
134128

135-
errors = r_json.get("errors", [])
129+
errors = response.get("errors", [])
136130

137131
def check_errors(keywords, *path):
138132
""" Helper that looks for any of the given `keywords` in any of
@@ -172,32 +166,16 @@ def check_errors(keywords, *path):
172166
graphql_error["message"])
173167

174168
# Check if API limit was exceeded
175-
response_msg = r_json.get("message", "")
169+
response_msg = response.get("message", "")
176170
if response_msg.startswith("You have exceeded"):
177171
raise labelbox.exceptions.ApiLimitError(response_msg)
178172

179-
prisma_error = check_errors(["INTERNAL_SERVER_ERROR"], "extensions",
180-
"code")
181-
if prisma_error:
182-
raise labelbox.exceptions.InternalServerError(
183-
prisma_error["message"])
184-
185173
if len(errors) > 0:
186174
logger.warning("Unparsed errors on query execution: %r", errors)
187175
raise labelbox.exceptions.LabelboxError("Unknown error: %s" %
188176
str(errors))
189177

190-
# if we do return a proper error code, and didn't catch this above
191-
# reraise
192-
# this mainly catches a 401 for API access disabled for free tier
193-
# TODO: need to unify API errors to handle things more uniformly
194-
# in the SDK
195-
if response.status_code != requests.codes.ok:
196-
message = f"{response.status_code} {response.reason}"
197-
cause = r_json.get('message')
198-
raise labelbox.exceptions.LabelboxError(message, cause)
199-
200-
return r_json["data"]
178+
return response["data"]
201179

202180
def upload_file(self, path: str) -> str:
203181
"""Uploads given path to local file.

labelbox/exceptions.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,6 @@ class ValidationFailedError(LabelboxError):
4848
pass
4949

5050

51-
class InternalServerError(LabelboxError):
52-
"""Nondescript prisma or 502 related errors.
53-
54-
Meant to be retryable.
55-
56-
TODO: these errors need better messages from platform
57-
"""
58-
pass
59-
60-
6151
class InvalidQueryError(LabelboxError):
6252
""" Indicates a malconstructed or unsupported query (either by GraphQL in
6353
general or by Labelbox specifically). This can be the result of either client

labelbox/schema/bulk_import_request.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,6 @@ def create_from_objects(cls, client, project_id: str, name: str,
222222
"""
223223
_validate_ndjson(predictions)
224224
data_str = ndjson.dumps(predictions)
225-
if not data_str:
226-
raise ValueError('annotations cannot be empty')
227-
228225
data = data_str.encode('utf-8')
229226
file_name = _make_file_name(project_id, name)
230227
request_data = _make_request_data(project_id, name, len(data_str),

labelbox/schema/project.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,16 +410,13 @@ def _is_url_valid(url: Union[str, Path]) -> bool:
410410
file=path,
411411
validate_file=True,
412412
)
413-
elif isinstance(annotations, Iterable):
413+
else:
414414
return BulkImportRequest.create_from_objects(
415415
client=self.client,
416416
project_id=self.uid,
417417
name=name,
418418
predictions=annotations, # type: ignore
419419
)
420-
else:
421-
raise ValueError(
422-
f'Invalid annotations given of type: {type(annotations)}')
423420

424421

425422
class LabelingParameterOverride(DbObject):

mypy.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@ ignore_missing_imports = True
33

44
[mypy-ndjson.*]
55
ignore_missing_imports = True
6-
7-
[mypy-google.*]
8-
ignore_missing_imports = True

setup.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@
55

66
setuptools.setup(
77
name="labelbox",
8-
version="2.4.5",
8+
version="2.4.4",
99
author="Labelbox",
1010
author_email="[email protected]",
1111
description="Labelbox Python API",
1212
long_description=long_description,
1313
long_description_content_type="text/markdown",
1414
url="https://labelbox.com",
1515
packages=setuptools.find_packages(),
16-
install_requires=[
17-
"backoff==1.10.0",
18-
"ndjson==0.3.1",
19-
"requests>=2.22.0",
20-
"google-api-core>=1.22.1",
21-
],
16+
install_requires=["backoff==1.10.0", "ndjson==0.3.1", "requests==2.22.0"],
2217
classifiers=[
2318
'Development Status :: 3 - Alpha',
2419
'License :: OSI Approved :: Apache Software License',

tests/integration/test_labeling_frontend.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33

44
def test_get_labeling_frontends(client):
55
frontends = list(client.get_labeling_frontends())
6-
assert len(frontends) >= 1, (
7-
'Projects should have at least one frontend by default.')
6+
assert len(frontends) == 1, frontends
87

98
# Test filtering
10-
target_frontend = frontends[0]
11-
filtered_frontends = client.get_labeling_frontends(
12-
where=LabelingFrontend.iframe_url_path ==
13-
target_frontend.iframe_url_path)
14-
for frontend in filtered_frontends:
15-
assert target_frontend == frontend
9+
single = list(
10+
client.get_labeling_frontends(where=LabelingFrontend.iframe_url_path ==
11+
frontends[0].iframe_url_path))
12+
assert len(single) == 1, single
1613

1714

1815
def test_labeling_frontend_connecting_to_project(project):

0 commit comments

Comments
 (0)