Skip to content
Draft
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
2 changes: 1 addition & 1 deletion packages/uipath-platform/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath-platform"
version = "0.2.34"
version = "0.2.35"
description = "HTTP client library for programmatic access to UiPath Platform"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
Expand Down
5 changes: 3 additions & 2 deletions packages/uipath-platform/src/uipath/platform/common/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import random

from httpx import ConnectTimeout, HTTPStatusError, Response, TimeoutException
from httpx import ConnectError, HTTPStatusError, Response, TimeoutException
from tenacity import RetryCallState

from ..errors import EnrichedException
Expand Down Expand Up @@ -67,7 +67,8 @@ def extract_retry_after_from_chain(exception: BaseException) -> float | None:

def is_retryable_platform_exception(exception: BaseException) -> bool:
"""Return True if the exception is transient and should be retried."""
if isinstance(exception, (ConnectTimeout, TimeoutException)):
# A failed connect never sent the request, so any method is safe to retry.
if isinstance(exception, (ConnectError, TimeoutException)):
return True
if isinstance(exception, EnrichedException):
return exception.status_code in RETRYABLE_STATUS_CODES
Expand Down
55 changes: 55 additions & 0 deletions packages/uipath-platform/tests/services/test_base_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import httpx
import pytest
from pytest_httpx import HTTPXMock

Expand Down Expand Up @@ -232,6 +233,41 @@ def test_502_retried(
assert response.status_code == 200
assert len(httpx_mock.get_requests()) == 2

def test_connect_error_retried(
self,
httpx_mock: HTTPXMock,
service: BaseService,
base_url: str,
org: str,
tenant: str,
):
url = self._url(base_url, org, tenant)
httpx_mock.add_exception(
httpx.ConnectError("[Errno 104] Connection reset by peer"), url=url
)
httpx_mock.add_response(url=url, status_code=200, json={"ok": True})

response = service.request("POST", "/endpoint")
assert response.status_code == 200
assert len(httpx_mock.get_requests()) == 2

def test_read_error_not_retried(
self,
httpx_mock: HTTPXMock,
service: BaseService,
base_url: str,
org: str,
tenant: str,
):
url = self._url(base_url, org, tenant)
httpx_mock.add_exception(
httpx.ReadError("[Errno 104] Connection reset by peer"), url=url
)

with pytest.raises(httpx.ReadError):
service.request("POST", "/endpoint")
assert len(httpx_mock.get_requests()) == 1

@pytest.mark.anyio
async def test_429_retried_async(
self,
Expand Down Expand Up @@ -266,6 +302,25 @@ async def test_503_retried_async(
assert response.status_code == 200
assert len(httpx_mock.get_requests()) == 2

@pytest.mark.anyio
async def test_connect_error_retried_async(
self,
httpx_mock: HTTPXMock,
service: BaseService,
base_url: str,
org: str,
tenant: str,
):
url = self._url(base_url, org, tenant)
httpx_mock.add_exception(
httpx.ConnectError("[Errno 104] Connection reset by peer"), url=url
)
httpx_mock.add_response(url=url, status_code=200, json={"ok": True})

response = await service.request_async("POST", "/endpoint")
assert response.status_code == 200
assert len(httpx_mock.get_requests()) == 2

@pytest.mark.anyio
async def test_400_not_retried_async(
self,
Expand Down
8 changes: 8 additions & 0 deletions packages/uipath-platform/tests/services/test_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ def test_timeout_exception(self):
err = httpx.TimeoutException("timed out")
assert is_retryable_platform_exception(err) is True

def test_connect_error(self):
err = httpx.ConnectError("[Errno 104] Connection reset by peer")
assert is_retryable_platform_exception(err) is True

def test_read_error_not_retryable(self):
err = httpx.ReadError("[Errno 104] Connection reset by peer")
assert is_retryable_platform_exception(err) is False

def test_enriched_408(self):
http_err = _make_http_status_error(408)
err = EnrichedException(http_err)
Expand Down
2 changes: 1 addition & 1 deletion packages/uipath-platform/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/uipath/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading