Skip to content

Commit 1920a94

Browse files
Merge pull request #278 from joaomarcoscrs/main
Fixes batches being created with `None` name
2 parents 4740a84 + 552e3e3 commit 1920a94

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

roboflow/adapters/rfapi.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ def upload_image(
5757
split (str): the dataset split the image to
5858
"""
5959

60+
coalesced_batch_name = batch_name or DEFAULT_BATCH_NAME
61+
6062
# If image is not a hosted image
6163
if not hosted_image:
6264
image_name = os.path.basename(image_path)
6365
imgjpeg = image_utils.file2jpeg(image_path)
6466

6567
upload_url = _local_upload_url(
66-
api_key, project_url, batch_name, tag_names, sequence_number, sequence_size, kwargs
68+
api_key, project_url, coalesced_batch_name, tag_names, sequence_number, sequence_size, kwargs
6769
)
6870
m = MultipartEncoder(
6971
fields={
@@ -77,7 +79,7 @@ def upload_image(
7779
else:
7880
# Hosted image upload url
7981

80-
upload_url = _hosted_upload_url(api_key, project_url, image_path, split, batch_name, tag_names)
82+
upload_url = _hosted_upload_url(api_key, project_url, image_path, split, coalesced_batch_name, tag_names)
8183
# Get response
8284
response = requests.post(upload_url, timeout=(300, 300))
8385
responsejson = None

tests/test_rfapi.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ def test_upload_image_local(self, mock_file2jpeg):
3535
f"&sequence_number=1&sequence_size=10&tag=lonely-tag"
3636
),
3737
},
38+
{
39+
"desc": "without batch_name",
40+
"expected_url": (
41+
f"{API_URL}/dataset/{self.PROJECT_URL}/upload?"
42+
f"api_key={self.API_KEY}&batch={urllib.parse.quote_plus(DEFAULT_BATCH_NAME)}"
43+
f"&sequence_number=1&sequence_size=10&tag=lonely-tag"
44+
),
45+
},
3846
{
3947
"desc": "without batch_name",
4048
"batch_name": None,
@@ -57,7 +65,7 @@ def test_upload_image_local(self, mock_file2jpeg):
5765
"tag_names": self.TAG_NAMES_LOCAL,
5866
}
5967

60-
if scenario["batch_name"] is not None:
68+
if "batch_name" in scenario:
6169
upload_image_payload["batch_name"] = scenario["batch_name"]
6270

6371
result = upload_image(self.API_KEY, self.PROJECT_URL, self.IMAGE_PATH_LOCAL, **upload_image_payload)
@@ -76,6 +84,15 @@ def test_upload_image_hosted(self):
7684
f"&batch=My%20batch&tag=tag1&tag=tag2"
7785
),
7886
},
87+
{
88+
"desc": "without batch_name",
89+
"expected_url": (
90+
f"{API_URL}/dataset/{self.PROJECT_URL}/upload?"
91+
f"api_key={self.API_KEY}&batch={urllib.parse.quote_plus(DEFAULT_BATCH_NAME)}"
92+
f"&name={self.IMAGE_NAME_HOSTED}&split=train"
93+
f"&image={urllib.parse.quote_plus(self.IMAGE_PATH_HOSTED)}&tag=tag1&tag=tag2"
94+
),
95+
},
7996
{
8097
"desc": "without batch_name",
8198
"batch_name": None,
@@ -98,7 +115,7 @@ def test_upload_image_hosted(self):
98115
"tag_names": self.TAG_NAMES_HOSTED,
99116
}
100117

101-
if scenario["batch_name"] is not None:
118+
if "batch_name" in scenario:
102119
upload_image_payload["batch_name"] = scenario["batch_name"]
103120

104121
result = upload_image(self.API_KEY, self.PROJECT_URL, self.IMAGE_PATH_HOSTED, **upload_image_payload)

0 commit comments

Comments
 (0)