Skip to content

Commit

Permalink
Fix the client sometimes would not retry (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pandede authored Nov 6, 2024
1 parent 4b40663 commit 39b2391
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion aiohttp_retry/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def _is_skip_retry(self, current_attempt: int, response: ClientResponse) -
if current_attempt == self._retry_options.attempts:
return True

if response.method not in self._retry_options.methods:
if response.method.upper() not in self._retry_options.methods:
return True

if response.status >= _MIN_SERVER_ERROR_STATUS and self._retry_options.retry_all_server_errors:
Expand Down
2 changes: 1 addition & 1 deletion aiohttp_retry/retry_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(

if methods is None:
methods = {"HEAD", "GET", "PUT", "DELETE", "OPTIONS", "TRACE", "POST", "CONNECT", "PATCH"}
self.methods: Iterable[str] = methods
self.methods: Iterable[str] = {method.upper() for method in methods}

self.retry_all_server_errors = retry_all_server_errors
self.evaluate_response_callback = evaluate_response_callback
Expand Down
13 changes: 12 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,18 @@ async def test_list_retry_works_for_multiple_attempts(aiohttp_client: pytest_aio
async def test_dont_retry_if_not_in_retry_methods(aiohttp_client: pytest_aiohttp.plugin.AiohttpClient) -> None:
retry_client, test_app = await get_retry_client_and_test_app_for_test(
aiohttp_client,
retry_options=ExponentialRetry(methods={"POST"}), # not "GET"
retry_options=ExponentialRetry(), # try on all methods by default
)

async with retry_client.get("/internal_error") as response:
assert response.status == 500
assert test_app.counter == 3

await retry_client.close()

retry_client, test_app = await get_retry_client_and_test_app_for_test(
aiohttp_client,
retry_options=ExponentialRetry(methods={"POST"}), # try on only POST method
)

async with retry_client.get("/internal_error") as response:
Expand Down

0 comments on commit 39b2391

Please sign in to comment.