Skip to content

Commit 51a907a

Browse files
author
Leandro Rosemberg
committed
Fix some bugs
1 parent 91afc0f commit 51a907a

File tree

3 files changed

+27
-34
lines changed

3 files changed

+27
-34
lines changed

roboflow/adapters/rfapi.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,15 @@ def upload_image(
102102

103103
if response.status_code != 200:
104104
if responsejson:
105-
message = responsejson.get("message") or responsejson
106-
raise ImageUploadError(message, status_code=response.status_code)
105+
err_msg = responsejson
106+
107+
if err_msg.get("error"):
108+
err_msg = err_msg["error"]
109+
110+
if err_msg.get("message"):
111+
err_msg = err_msg["message"]
112+
113+
raise ImageUploadError(err_msg, status_code=response.status_code)
107114
else:
108115
raise ImageUploadError(response, status_code=response.status_code)
109116

@@ -224,9 +231,9 @@ def _save_annotation_error(response):
224231
return AnnotationSaveError(response, status_code=response.status_code)
225232

226233
if responsejson.get("error"):
227-
return AnnotationSaveError(responsejson["error"], status_code=response.status_code)
228-
229-
if responsejson.get("message"):
230-
return AnnotationSaveError(responsejson["message"], status_code=response.status_code)
234+
err_msg = responsejson["error"]
235+
if err_msg.get("message"):
236+
err_msg = err_msg["message"]
237+
return AnnotationSaveError(err_msg, status_code=response.status_code)
231238

232239
return AnnotationSaveError(responsejson, status_code=response.status_code)

roboflow/core/workspace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def _log_img_upload(
317317
img_duplicate = image.get("duplicate")
318318

319319
upload_time_str = f"[{image_upload_time:.1f}s]"
320-
annotation_time_str = f"[{annotation_time:.1f}s]"
320+
annotation_time_str = f"[{annotation_time:.1f}s]" if annotation_time else ""
321321
retry_attempts = f" (with {image_upload_retry_attempts} retries)" if image_upload_retry_attempts > 0 else ""
322322

323323
if img_duplicate:
@@ -366,7 +366,7 @@ def _save_annotation(image_id, imagedesc):
366366
labelmap = load_labelmap(labelmap)
367367

368368
if not annotation_path:
369-
return
369+
return None, None
370370

371371
annotation, upload_time = project.save_annotation(
372372
annotation_path=annotation_path,

tests/test_project.py

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,16 @@ def test_check_valid_image_with_unaccepted_formats(self):
2727
for image in images_to_test:
2828
self.assertFalse(self.project.check_valid_image(f"tests/images/{image}"))
2929

30-
def test_upload_raises_upload_image_error_response_200(self):
30+
def test_upload_raises_upload_image_error(self):
3131
responses.add(
3232
responses.POST,
3333
f"{API_URL}/dataset/{PROJECT_NAME}/upload?api_key={ROBOFLOW_API_KEY}" f"&batch={DEFAULT_BATCH_NAME}",
3434
json={
35-
"message": "Invalid Image",
36-
"type": "InvalidImageException",
37-
},
38-
status=200,
39-
)
40-
41-
with self.assertRaises(ImageUploadError) as error:
42-
self.project.upload(
43-
"tests/images/rabbit.JPG",
44-
annotation_path="tests/annotations/valid_annotation.json",
45-
)
46-
47-
self.assertEqual(str(error.exception), "Invalid Image")
48-
49-
def test_upload_raises_upload_image_error_response_400(self):
50-
responses.add(
51-
responses.POST,
52-
f"{API_URL}/dataset/{PROJECT_NAME}/upload?api_key={ROBOFLOW_API_KEY}" f"&batch={DEFAULT_BATCH_NAME}",
53-
json={
54-
"message": "Invalid Image",
55-
"type": "InvalidImageException",
35+
"error": {
36+
"message": "Invalid image.",
37+
"type": "InvalidImageException",
38+
"hint": "This image was already annotated; to overwrite the annotation, pass overwrite=true..."
39+
}
5640
},
5741
status=400,
5842
)
@@ -63,7 +47,7 @@ def test_upload_raises_upload_image_error_response_400(self):
6347
annotation_path="tests/annotations/valid_annotation.json",
6448
)
6549

66-
self.assertEqual(str(error.exception), "Invalid Image")
50+
self.assertEqual(str(error.exception), "Invalid image.")
6751

6852
def test_upload_raises_upload_annotation_error(self):
6953
image_id = "hbALkCFdNr9rssgOUXug"
@@ -82,9 +66,11 @@ def test_upload_raises_upload_annotation_error(self):
8266
responses.POST,
8367
f"{API_URL}/dataset/{PROJECT_NAME}/annotate/{image_id}?api_key={ROBOFLOW_API_KEY}" f"&name={image_name}",
8468
json={
85-
"message": "Image was already annotated.",
86-
"type": "InvalidImageException",
87-
"hint": "This image was already annotated; to overwrite the annotation, pass overwrite=true...",
69+
"error": {
70+
"message": "Image was already annotated.",
71+
"type": "InvalidImageException",
72+
"hint": "This image was already annotated; to overwrite the annotation, pass overwrite=true..."
73+
}
8874
},
8975
status=400,
9076
)

0 commit comments

Comments
 (0)