Skip to content
Open
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
8 changes: 8 additions & 0 deletions .hark/changes/2026-11-13_stripe-openapi_91b8332e.change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Update generated code
pr_url: https://github.com/stripe/stripe-python/pull/1964
semver_level: minor
is_stripe_api_change: true
---

* Release specs are identical.
2 changes: 1 addition & 1 deletion CODEGEN_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
65c49b0893d71e8cfe272b2d38cd3307ee1833f2
087107391e4d36a11e317f83346d27cabfa71bb8
2 changes: 1 addition & 1 deletion OPENAPI_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2596
v2600
9 changes: 7 additions & 2 deletions stripe/_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,12 +858,17 @@ def __init__(
proxy: Optional[HTTPClient._Proxy] = None,
async_fallback_client: Optional[HTTPClient] = None,
_lib=None, # used for internal unit testing
*,
timeout: int = 80,
connect_timeout: int = 30,
):
super(PycurlClient, self).__init__(
verify_ssl_certs=verify_ssl_certs,
proxy=proxy,
async_fallback_client=async_fallback_client,
)
self._timeout = timeout
self._connect_timeout = connect_timeout

if _lib is None:
import pycurl # pyright: ignore[reportMissingModuleSource]
Expand Down Expand Up @@ -985,8 +990,8 @@ def _request_internal(
curl.setopt(self.pycurl.WRITEFUNCTION, b.write)
curl.setopt(self.pycurl.HEADERFUNCTION, rheaders.write)
curl.setopt(self.pycurl.NOSIGNAL, 1)
curl.setopt(self.pycurl.CONNECTTIMEOUT, 30)
curl.setopt(self.pycurl.TIMEOUT, 80)
curl.setopt(self.pycurl.CONNECTTIMEOUT, self._connect_timeout)
curl.setopt(self.pycurl.TIMEOUT, self._timeout)
_assert_no_header_injection(headers)
curl.setopt(
self.pycurl.HTTPHEADER,
Expand Down
101 changes: 101 additions & 0 deletions tests/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,107 @@ def test_request_rejects_header_injection(
with pytest.raises(ValueError):
make_request("get", self.valid_url, headers, None)

@pytest.mark.parametrize(
"client_kwargs,expected_connect_timeout,expected_timeout",
[
({}, 30, 80),
({"connect_timeout": 5, "timeout": 10}, 5, 10),
({"connect_timeout": 5}, 5, 80),
({"timeout": 10}, 30, 10),
],
)
def test_timeout(
self,
mocked_request_lib,
mock_response,
make_request,
client_kwargs,
expected_connect_timeout,
expected_timeout,
):
mock_response(mocked_request_lib, '{"foo": "baz"}', 200)
make_request(
"GET", self.valid_url, {}, None, client_kwargs=client_kwargs
)

curl_mock = mocked_request_lib.Curl()
curl_mock.setopt.assert_any_call(
mocked_request_lib.CONNECTTIMEOUT, expected_connect_timeout
)
curl_mock.setopt.assert_any_call(
mocked_request_lib.TIMEOUT, expected_timeout
)

def test_timeout_stream(
self, mocked_request_lib, mock_response, make_streamed_request
):
mock_response(mocked_request_lib, "some streamed content", 200)
make_streamed_request(
"GET",
self.valid_url,
{},
None,
client_kwargs={"connect_timeout": 5, "timeout": 10},
)

curl_mock = mocked_request_lib.Curl()
curl_mock.setopt.assert_any_call(mocked_request_lib.CONNECTTIMEOUT, 5)
curl_mock.setopt.assert_any_call(mocked_request_lib.TIMEOUT, 10)

def test_timeout_reapplied_after_reset(
self, mocked_request_lib, mock_response, make_client
):
mock_response(mocked_request_lib, '{"foo": "baz"}', 200)
client = make_client(connect_timeout=5, timeout=10)

client.request("get", self.valid_url, {})
client.request("get", self.valid_url, {})

curl_mock = mocked_request_lib.Curl()
# reset() clears every option, so each request must set the
# timeouts again after its own reset() call.
relevant_calls = [
c
for c in curl_mock.mock_calls
if c == call.reset()
or (
c[0] == "setopt"
and c[1][0]
in (
mocked_request_lib.CONNECTTIMEOUT,
mocked_request_lib.TIMEOUT,
)
)
]
assert (
relevant_calls
== [
call.reset(),
call.setopt(mocked_request_lib.CONNECTTIMEOUT, 5),
call.setopt(mocked_request_lib.TIMEOUT, 10),
]
* 2
)

def test_positional_args(self, mocked_request_lib):
client = self.REQUEST_CLIENT(False, None, None, mocked_request_lib)

assert client.pycurl is mocked_request_lib
assert client._verify_ssl_certs is False
assert client._connect_timeout == 30
assert client._timeout == 80

# Timeouts are keyword-only so they can't be confused with each
# other or with the existing positional parameters.
with pytest.raises(TypeError):
self.REQUEST_CLIENT(
False,
None,
None,
mocked_request_lib,
10, # pyright: ignore[reportGeneralTypeIssues]
)

@pytest.fixture
def created_curls(self, mocked_request_lib):
curls: List[Mock] = []
Expand Down
Loading