Skip to content

Commit c885c17

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
chore(client): validate that max_retries is not None (#218)
1 parent a4ede0e commit c885c17

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/orb/_base_client.py

+5
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ def __init__(
361361
self._strict_response_validation = _strict_response_validation
362362
self._idempotency_header = None
363363

364+
if max_retries is None: # pyright: ignore[reportUnnecessaryComparison]
365+
raise TypeError(
366+
"max_retries cannot be None. If you want to disable retries, pass `0`; if you want unlimited retries, pass `math.inf` or a very high number; if you want the default behavior, pass `orb-billing.DEFAULT_MAX_RETRIES`"
367+
)
368+
364369
def _enforce_trailing_slash(self, url: URL) -> URL:
365370
if url.raw_path.endswith(b"/"):
366371
return url

tests/test_client.py

+8
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,10 @@ class Model(BaseModel):
668668

669669
assert isinstance(exc.value.__cause__, ValidationError)
670670

671+
def test_client_max_retries_validation(self) -> None:
672+
with pytest.raises(TypeError, match=r"max_retries cannot be None"):
673+
Orb(base_url=base_url, api_key=api_key, _strict_response_validation=True, max_retries=cast(Any, None))
674+
671675
@pytest.mark.respx(base_url=base_url)
672676
def test_received_text_for_expected_json(self, respx_mock: MockRouter) -> None:
673677
class Model(BaseModel):
@@ -1380,6 +1384,10 @@ class Model(BaseModel):
13801384

13811385
assert isinstance(exc.value.__cause__, ValidationError)
13821386

1387+
async def test_client_max_retries_validation(self) -> None:
1388+
with pytest.raises(TypeError, match=r"max_retries cannot be None"):
1389+
AsyncOrb(base_url=base_url, api_key=api_key, _strict_response_validation=True, max_retries=cast(Any, None))
1390+
13831391
@pytest.mark.respx(base_url=base_url)
13841392
@pytest.mark.asyncio
13851393
async def test_received_text_for_expected_json(self, respx_mock: MockRouter) -> None:

0 commit comments

Comments
 (0)