Skip to content

Commit d2ffdac

Browse files
timmarkhuffTim HuffAuto-format Bot
authored
Restoring timeout functionality (#184)
* adding back timeout * adding a test * Automatically reformatting code * responding to pr feedback, increasing timeout slightly * Automatically reformatting code --------- Co-authored-by: Tim Huff <[email protected]> Co-authored-by: Auto-format Bot <[email protected]>
1 parent daed60d commit d2ffdac

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ packages = [
99
{include = "**/*.py", from = "src"},
1010
]
1111
readme = "README.md"
12-
version = "0.14.0"
12+
version = "0.14.1"
1313

1414
[tool.poetry.dependencies]
1515
# For certifi, use ">=" instead of "^" since it upgrades its "major version" every year, not really following semver

src/groundlight/client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
# Set urllib3 request timeout to something modern and fast.
4040
# The system defaults can be stupidly long
4141
# It used to take >8 min to timeout to a bad IP address
42-
DEFAULT_REQUEST_TIMEOUT = 5
42+
DEFAULT_REQUEST_TIMEOUT = 10 # seconds
4343

4444

4545
class GroundlightClientError(Exception):
@@ -427,14 +427,15 @@ def submit_image_query( # noqa: PLR0913 # pylint: disable=too-many-arguments, t
427427

428428
image_bytesio: ByteStreamWrapper = parse_supported_image_types(image)
429429

430-
params = {"detector_id": detector_id, "body": image_bytesio}
430+
params = {"detector_id": detector_id, "body": image_bytesio, "_request_timeout": DEFAULT_REQUEST_TIMEOUT}
431+
431432
if patience_time is not None:
432433
params["patience_time"] = patience_time
433434

434435
if human_review is not None:
435436
params["human_review"] = human_review
436437

437-
if inspection_id is not None:
438+
if inspection_id: # consider an empty string to mean there is no inspection
438439
params["inspection_id"] = inspection_id
439440

440441
if want_async is True:

test/integration/test_groundlight.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,3 +796,15 @@ def test_submit_image_query_with_inspection_id_metadata_and_want_async(gl: Groun
796796

797797
assert iq.metadata == metadata
798798
assert iq.result.label == Label.YES
799+
800+
801+
def test_submit_image_query_with_empty_inspection_id(gl: Groundlight, detector: Detector, image: str):
802+
"""The URCap submits the inspection_id as an empty string when there is no active inspection.
803+
This test ensures that this behavior is allowed and does not raise an exception.
804+
"""
805+
gl.submit_image_query(
806+
detector=detector.id,
807+
image=image,
808+
human_review="NEVER",
809+
inspection_id="",
810+
)

0 commit comments

Comments
 (0)