Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ All notable changes to this project will be documented in this file.
warning. Before, its rows were sent as the annotation of every image they
named, which failed the save, even when the folder's annotation CSV also
listed the image ([#583](https://github.com/roboflow/roboflow-python/pull/583)).
- `Project.upload()` raises `ImageUploadError` with the API's text and status
code when a failed image upload answers `{"error": "<text>"}`, for example a
503 from an instance that is shutting down, so `num_retry_uploads` retries it.
Before, the upload crashed with
`AttributeError: 'str' object has no attribute 'get'` and was not retried
([#586](https://github.com/roboflow/roboflow-python/pull/586)).

## 1.7.3

Expand Down
2 changes: 1 addition & 1 deletion roboflow/adapters/rfapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ def upload_image(
if err_msg.get("error"):
err_msg = err_msg["error"]

if err_msg.get("message"):
if isinstance(err_msg, dict) and err_msg.get("message"):
err_msg = err_msg["message"]

raise ImageUploadError(err_msg, status_code=response.status_code)
Expand Down
23 changes: 23 additions & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,29 @@ def test_upload_raises_upload_image_error(self):

self.assertEqual(str(error.exception), "Invalid image.")

UPLOAD_URL = f"{API_URL}/dataset/{PROJECT_NAME}/upload?api_key={ROBOFLOW_API_KEY}&batch={DEFAULT_BATCH_NAME}"

def test_upload_raises_upload_image_error_for_a_string_error(self):
responses.add(responses.POST, self.UPLOAD_URL, json={"error": "Instance recycling"}, status=503)

with self.assertRaises(ImageUploadError) as error:
self.project.upload("tests/images/rabbit.JPG")

self.assertEqual(str(error.exception), "Instance recycling")
self.assertEqual(error.exception.status_code, 503)

def test_upload_retries_after_a_string_error(self):
responses.add(responses.POST, self.UPLOAD_URL, json={"error": "Instance recycling"}, status=503)
responses.add(responses.POST, self.UPLOAD_URL, json={"success": True, "id": "img-1"}, status=200)

with patch("roboflow.util.general.time.sleep"):
result = self.project.upload("tests/images/rabbit.JPG", num_retry_uploads=2)

self.assertEqual(result[0]["image"]["id"], "img-1")
self.assertEqual(result[0]["upload_retry_attempts"], 1)
upload_posts = [call for call in responses.calls if f"/dataset/{PROJECT_NAME}/upload?" in call.request.url]
self.assertEqual(len(upload_posts), 2)

def test_upload_raises_upload_annotation_error(self):
image_id = "hbALkCFdNr9rssgOUXug"
image_name = "invalid_annotation.json"
Expand Down
Loading