Skip to content

Commit aad62f9

Browse files
fix: disable automatic vault operation retries in SDKs
Stainless-Generated-From: 068a33988f678bd0ddafaacdda5828037155b2ed
1 parent 0737fe9 commit aad62f9

2 files changed

Lines changed: 76 additions & 2 deletions

File tree

src/kernel/resources/vaults/items.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ def perform_operation(
615615
raise ValueError(f"Expected a non-empty value for `key` but received {key!r}")
616616
return cast(
617617
VaultItemOperationResponse,
618-
self._post(
618+
self._client.with_options(max_retries=0).post(
619619
path_template("/vaults/{id_or_name}/items/{key}/operations", id_or_name=id_or_name, key=key),
620620
body=maybe_transform(
621621
{
@@ -1378,7 +1378,7 @@ async def perform_operation(
13781378
raise ValueError(f"Expected a non-empty value for `key` but received {key!r}")
13791379
return cast(
13801380
VaultItemOperationResponse,
1381-
await self._post(
1381+
await self._client.with_options(max_retries=0).post(
13821382
path_template("/vaults/{id_or_name}/items/{key}/operations", id_or_name=id_or_name, key=key),
13831383
body=await async_maybe_transform(
13841384
{
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
from __future__ import annotations
2+
3+
import httpx
4+
import pytest
5+
6+
from kernel import Kernel, AsyncKernel, APIStatusError, APIConnectionError
7+
8+
9+
@pytest.mark.parametrize("failure", ["connection", 409, 429, 500])
10+
def test_fill_does_not_retry(failure: str | int) -> None:
11+
calls = 0
12+
13+
def handle(request: httpx.Request) -> httpx.Response:
14+
nonlocal calls
15+
calls += 1
16+
if isinstance(failure, str):
17+
raise httpx.ReadError("connection lost", request=request)
18+
return httpx.Response(failure, json={})
19+
20+
with Kernel(
21+
api_key="test", max_retries=1, http_client=httpx.Client(transport=httpx.MockTransport(handle))
22+
) as client:
23+
with pytest.raises((APIConnectionError, APIStatusError)):
24+
client.vaults.items.perform_operation(
25+
"login",
26+
id_or_name="vault",
27+
type="fill",
28+
browser_id="browser",
29+
fields=[{"field": "password", "selector": "#password"}],
30+
)
31+
assert calls == 1
32+
assert client.max_retries == 1
33+
34+
35+
@pytest.mark.parametrize("failure", ["connection", 409, 429, 500])
36+
async def test_async_fill_does_not_retry(failure: str | int) -> None:
37+
calls = 0
38+
39+
def handle(request: httpx.Request) -> httpx.Response:
40+
nonlocal calls
41+
calls += 1
42+
if isinstance(failure, str):
43+
raise httpx.ReadError("connection lost", request=request)
44+
return httpx.Response(failure, json={})
45+
46+
async with AsyncKernel(
47+
api_key="test", max_retries=1, http_client=httpx.AsyncClient(transport=httpx.MockTransport(handle))
48+
) as client:
49+
with pytest.raises((APIConnectionError, APIStatusError)):
50+
await client.vaults.items.perform_operation(
51+
"login",
52+
id_or_name="vault",
53+
type="fill",
54+
browser_id="browser",
55+
fields=[{"field": "password", "selector": "#password"}],
56+
)
57+
assert calls == 1
58+
assert client.max_retries == 1
59+
60+
61+
def test_reads_keep_client_retries() -> None:
62+
calls = 0
63+
64+
def handle(request: httpx.Request) -> httpx.Response:
65+
nonlocal calls
66+
calls += 1
67+
raise httpx.ReadError("connection lost", request=request)
68+
69+
with Kernel(
70+
api_key="test", max_retries=1, http_client=httpx.Client(transport=httpx.MockTransport(handle))
71+
) as client:
72+
with pytest.raises(APIConnectionError):
73+
client.vaults.items.retrieve("login", id_or_name="vault")
74+
assert calls == 2

0 commit comments

Comments
 (0)