Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes batches being created with None name #278

Merged
merged 1 commit into from
Jul 1, 2024
Merged
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: 4 additions & 2 deletions roboflow/adapters/rfapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ def upload_image(
split (str): the dataset split the image to
"""

coalesced_batch_name = batch_name or DEFAULT_BATCH_NAME

# If image is not a hosted image
if not hosted_image:
image_name = os.path.basename(image_path)
imgjpeg = image_utils.file2jpeg(image_path)

upload_url = _local_upload_url(
api_key, project_url, batch_name, tag_names, sequence_number, sequence_size, kwargs
api_key, project_url, coalesced_batch_name, tag_names, sequence_number, sequence_size, kwargs
)
m = MultipartEncoder(
fields={
Expand All @@ -77,7 +79,7 @@ def upload_image(
else:
# Hosted image upload url

upload_url = _hosted_upload_url(api_key, project_url, image_path, split, batch_name, tag_names)
upload_url = _hosted_upload_url(api_key, project_url, image_path, split, coalesced_batch_name, tag_names)
# Get response
response = requests.post(upload_url, timeout=(300, 300))
responsejson = None
Expand Down
21 changes: 19 additions & 2 deletions tests/test_rfapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def test_upload_image_local(self, mock_file2jpeg):
f"&sequence_number=1&sequence_size=10&tag=lonely-tag"
),
},
{
"desc": "without batch_name",
"expected_url": (
f"{API_URL}/dataset/{self.PROJECT_URL}/upload?"
f"api_key={self.API_KEY}&batch={urllib.parse.quote_plus(DEFAULT_BATCH_NAME)}"
f"&sequence_number=1&sequence_size=10&tag=lonely-tag"
),
},
{
"desc": "without batch_name",
"batch_name": None,
Expand All @@ -57,7 +65,7 @@ def test_upload_image_local(self, mock_file2jpeg):
"tag_names": self.TAG_NAMES_LOCAL,
}

if scenario["batch_name"] is not None:
if "batch_name" in scenario:
upload_image_payload["batch_name"] = scenario["batch_name"]

result = upload_image(self.API_KEY, self.PROJECT_URL, self.IMAGE_PATH_LOCAL, **upload_image_payload)
Expand All @@ -76,6 +84,15 @@ def test_upload_image_hosted(self):
f"&batch=My%20batch&tag=tag1&tag=tag2"
),
},
{
"desc": "without batch_name",
"expected_url": (
f"{API_URL}/dataset/{self.PROJECT_URL}/upload?"
f"api_key={self.API_KEY}&batch={urllib.parse.quote_plus(DEFAULT_BATCH_NAME)}"
f"&name={self.IMAGE_NAME_HOSTED}&split=train"
f"&image={urllib.parse.quote_plus(self.IMAGE_PATH_HOSTED)}&tag=tag1&tag=tag2"
),
},
{
"desc": "without batch_name",
"batch_name": None,
Expand All @@ -98,7 +115,7 @@ def test_upload_image_hosted(self):
"tag_names": self.TAG_NAMES_HOSTED,
}

if scenario["batch_name"] is not None:
if "batch_name" in scenario:
upload_image_payload["batch_name"] = scenario["batch_name"]

result = upload_image(self.API_KEY, self.PROJECT_URL, self.IMAGE_PATH_HOSTED, **upload_image_payload)
Expand Down
Loading