Skip to content

Commit 55b6b95

Browse files
author
Leandro Rosemberg
committed
Add retry attempts to ImageUploadError
1 parent 5606be4 commit 55b6b95

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

roboflow/adapters/rfapi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ImageUploadError(RoboflowError):
2222
def __init__(self, message, status_code=None):
2323
self.message = message
2424
self.status_code = status_code
25+
self.retries = 0
2526
super().__init__(self.message)
2627

2728

roboflow/core/project.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -482,23 +482,28 @@ def upload_image(
482482
project_url = self.id.rsplit("/")[1]
483483

484484
t0 = time.time()
485+
upload_retry_attempts = 0
485486
retry = Retry(num_retry_uploads, ImageUploadError)
486487

487-
image = retry(
488-
rfapi.upload_image,
489-
self.__api_key,
490-
project_url,
491-
image_path,
492-
hosted_image=hosted_image,
493-
split=split,
494-
batch_name=batch_name,
495-
tag_names=tag_names,
496-
sequence_number=sequence_number,
497-
sequence_size=sequence_size,
498-
**kwargs,
499-
)
488+
try:
489+
image = retry(
490+
rfapi.upload_image,
491+
self.__api_key,
492+
project_url,
493+
image_path,
494+
hosted_image=hosted_image,
495+
split=split,
496+
batch_name=batch_name,
497+
tag_names=tag_names,
498+
sequence_number=sequence_number,
499+
sequence_size=sequence_size,
500+
**kwargs,
501+
)
502+
upload_retry_attempts = retry.retries
503+
except ImageUploadError as e:
504+
e.retries = upload_retry_attempts
505+
raise e
500506

501-
upload_retry_attempts = retry.retries
502507
upload_time = time.time() - t0
503508

504509
return image, upload_time, upload_retry_attempts
@@ -508,7 +513,7 @@ def save_annotation(
508513
annotation_path=None,
509514
annotation_labelmap=None,
510515
image_id=None,
511-
batch_name=None,
516+
job_name=None,
512517
is_prediction: bool = False,
513518
annotation_overwrite=False,
514519
):
@@ -522,7 +527,7 @@ def save_annotation(
522527
annotation_name, # type: ignore[type-var]
523528
annotation_str, # type: ignore[type-var]
524529
image_id,
525-
job_name=batch_name, # type: ignore[type-var]
530+
job_name=job_name, # type: ignore[type-var]
526531
is_prediction=is_prediction,
527532
annotation_labelmap=annotation_labelmap,
528533
overwrite=annotation_overwrite,

0 commit comments

Comments
 (0)