From 8201bd4c1ed5a12ef49e4296ca511251e23e459f Mon Sep 17 00:00:00 2001 From: Akshaya Shanbhogue Date: Mon, 29 Dec 2025 15:32:10 -0800 Subject: [PATCH] fix(FasterDUTests): faster document understanding tests Also, fixing a bug where a sync method is invoked inside an async implementation. --- pyproject.toml | 2 +- .../platform/documents/_documents_service.py | 30 +++++++++++-------- tests/sdk/services/test_documents_service.py | 2 ++ uv.lock | 2 +- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6ee8e4f3c..8ba033b00 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "uipath" -version = "2.3.1" +version = "2.3.2" description = "Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools." readme = { file = "README.md", content-type = "text/markdown" } requires-python = ">=3.11" diff --git a/src/uipath/platform/documents/_documents_service.py b/src/uipath/platform/documents/_documents_service.py index 5fa391e4e..480672356 100644 --- a/src/uipath/platform/documents/_documents_service.py +++ b/src/uipath/platform/documents/_documents_service.py @@ -124,8 +124,12 @@ def __init__( self, config: UiPathApiConfig, execution_context: UiPathExecutionContext, + polling_interval: float = POLLING_INTERVAL, + polling_timeout: float = POLLING_TIMEOUT, ) -> None: super().__init__(config=config, execution_context=execution_context) + self.polling_interval = polling_interval + self.polling_timeout = polling_timeout def _get_common_headers(self) -> Dict[str, str]: return { @@ -479,12 +483,14 @@ async def _start_extraction_async( f"/du_/api/framework/projects/{project_id}/{tag}/document-types/{document_type_id}/extraction/start" ) - operation_id = self.request( - "POST", - url=url, - params={"api-version": 1.1}, - headers=self._get_common_headers(), - json={"documentId": document_id}, + operation_id = ( + await self.request_async( + "POST", + url=url, + params={"api-version": 1.1}, + headers=self._get_common_headers(), + json={"documentId": document_id}, + ) ).json()["operationId"] return StartExtractionResponse( @@ -506,13 +512,13 @@ def _wait_for_operation( while ( status in wait_statuses - and (time.monotonic() - start_time) < POLLING_TIMEOUT + and (time.monotonic() - start_time) < self.polling_timeout ): status, error, result = result_getter() - time.sleep(POLLING_INTERVAL) + time.sleep(self.polling_interval) if status != success_status: - if time.monotonic() - start_time >= POLLING_TIMEOUT: + if time.monotonic() - start_time >= self.polling_timeout: raise TimeoutError("Operation timed out.") raise RuntimeError( f"Operation failed with status: {status}, error: {error}" @@ -534,13 +540,13 @@ async def _wait_for_operation_async( while ( status in wait_statuses - and (time.monotonic() - start_time) < POLLING_TIMEOUT + and (time.monotonic() - start_time) < self.polling_timeout ): status, error, result = await result_getter() - await asyncio.sleep(POLLING_INTERVAL) + await asyncio.sleep(self.polling_interval) if status != success_status: - if time.monotonic() - start_time >= POLLING_TIMEOUT: + if time.monotonic() - start_time >= self.polling_timeout: raise TimeoutError("Operation timed out.") raise RuntimeError( f"Operation failed with status: {status}, error: {error}" diff --git a/tests/sdk/services/test_documents_service.py b/tests/sdk/services/test_documents_service.py index 9f0cb1cd8..436a9770f 100644 --- a/tests/sdk/services/test_documents_service.py +++ b/tests/sdk/services/test_documents_service.py @@ -30,6 +30,8 @@ def service( return DocumentsService( config=config, execution_context=execution_context, + polling_interval=0.001, # 1ms for fast tests + polling_timeout=10, # 10 seconds for tests ) diff --git a/uv.lock b/uv.lock index 727e3b946..e4c400155 100644 --- a/uv.lock +++ b/uv.lock @@ -2477,7 +2477,7 @@ wheels = [ [[package]] name = "uipath" -version = "2.3.1" +version = "2.3.2" source = { editable = "." } dependencies = [ { name = "click" },