Skip to content

Commit ff29d09

Browse files
authored
fix: handle empty SDK request headers (#2343)
1 parent 55e777a commit ff29d09

2 files changed

Lines changed: 44 additions & 3 deletions

File tree

inference_sdk/http/utils/request_building.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ def assembly_request_data(
120120
elif image_placement is ImagePlacement.DATA:
121121
data = batch_inference_inputs[0][0]
122122
else:
123-
raise NotImplemented(
123+
raise NotImplementedError(
124124
f"Not implemented request building method for {image_placement}"
125125
)
126126
scaling_factors = [e[1] for e in batch_inference_inputs]
127127

128128
execution_id_value = execution_id.get()
129129
if execution_id_value:
130-
headers = headers.copy()
130+
headers = headers.copy() if headers is not None else {}
131131
headers[EXECUTION_ID_HEADER] = execution_id_value
132132
if ENABLE_INTERNAL_REMOTE_EXEC_HEADER:
133133
_internal_secret = os.getenv("ROBOFLOW_INTERNAL_SERVICE_SECRET")

tests/inference_sdk/unit_tests/http/utils/test_request_building.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
import pytest
44

5-
from inference_sdk.config import INTERNAL_REMOTE_EXEC_REQ_HEADER, execution_id
5+
from inference_sdk.config import (
6+
EXECUTION_ID_HEADER,
7+
INTERNAL_REMOTE_EXEC_REQ_HEADER,
8+
execution_id,
9+
)
610
from inference_sdk.http.utils.request_building import (
711
ImagePlacement,
812
RequestData,
@@ -156,6 +160,43 @@ def test_prepare_requests_data() -> None:
156160
)
157161

158162

163+
def test_assembly_request_data_when_execution_id_is_set_and_headers_are_empty() -> None:
164+
# given
165+
token = execution_id.set("test-exec-id")
166+
167+
try:
168+
# when
169+
result = assembly_request_data(
170+
url="https://some.com",
171+
batch_inference_inputs=[("image_1", None)],
172+
headers=None,
173+
parameters=None,
174+
payload=None,
175+
image_placement=ImagePlacement.DATA,
176+
)
177+
178+
# then
179+
assert result.headers == {EXECUTION_ID_HEADER: "test-exec-id"}
180+
finally:
181+
execution_id.reset(token)
182+
183+
184+
def test_assembly_request_data_when_image_placement_is_not_supported() -> None:
185+
# when / then
186+
with pytest.raises(
187+
NotImplementedError,
188+
match="Not implemented request building method",
189+
):
190+
assembly_request_data(
191+
url="https://some.com",
192+
batch_inference_inputs=[("image_1", None)],
193+
headers=None,
194+
parameters=None,
195+
payload=None,
196+
image_placement=object(),
197+
)
198+
199+
159200
class TestInternalRemoteExecHeader:
160201
@patch(
161202
"inference_sdk.http.utils.request_building.ENABLE_INTERNAL_REMOTE_EXEC_HEADER",

0 commit comments

Comments
 (0)