Skip to content

Commit 85d65b1

Browse files
authored
Merge pull request #408 from UiPath/fix/rollback
fix: rollback to FoldersNavigation usage
2 parents 1a0f80e + 5ca4f8c commit 85d65b1

5 files changed

Lines changed: 281 additions & 46 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath"
3-
version = "2.0.67"
3+
version = "2.0.68"
44
description = "Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools."
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.10"

src/uipath/_services/folder_service.py

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,58 @@ def retrieve_key_by_folder_path(self, folder_path: str) -> Optional[str]:
2828

2929
@traced(name="folder_retrieve_key", run_type="uipath")
3030
def retrieve_key(self, *, folder_path: str) -> Optional[str]:
31-
spec = self._retrieve_spec(folder_path)
32-
response = self.request(
33-
spec.method,
34-
url=spec.endpoint,
35-
params=spec.params,
36-
).json()
37-
try:
38-
return response["value"][0]["Key"]
39-
except KeyError:
40-
return None
41-
42-
def _retrieve_spec(self, folder_path: str) -> RequestSpec:
31+
"""Retrieve the folder key by folder path with pagination support.
32+
33+
Args:
34+
folder_path: The fully qualified folder path to search for.
35+
36+
Returns:
37+
The folder key if found, None otherwise.
38+
"""
39+
skip = 0
40+
take = 20
41+
42+
while True:
43+
spec = self._retrieve_spec(folder_path, skip=skip, take=take)
44+
response = self.request(
45+
spec.method,
46+
url=spec.endpoint,
47+
params=spec.params,
48+
).json()
49+
50+
# Search for the folder in current page
51+
folder_key = next(
52+
(
53+
item["Key"]
54+
for item in response["PageItems"]
55+
if item["FullyQualifiedName"] == folder_path
56+
),
57+
None,
58+
)
59+
60+
if folder_key is not None:
61+
return folder_key
62+
63+
page_items = response["PageItems"]
64+
if len(page_items) < take:
65+
break
66+
67+
skip += take
68+
69+
return None
70+
71+
def _retrieve_spec(
72+
self, folder_path: str, *, skip: int = 0, take: int = 20
73+
) -> RequestSpec:
4374
folder_name = folder_path.split("/")[-1]
4475
return RequestSpec(
4576
method="GET",
46-
endpoint=Endpoint("orchestrator_/odata/Folders"),
77+
endpoint=Endpoint(
78+
"orchestrator_/api/FoldersNavigation/GetFoldersForCurrentUser"
79+
),
4780
params={
48-
"$filter": f"DisplayName eq '{folder_name}'",
49-
"$top": 1,
50-
"$select": "Key",
81+
"searchText": folder_name,
82+
"skip": skip,
83+
"take": take,
5184
},
5285
)

tests/sdk/services/test_context_grounding_service.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ def test_search(
3838
version: str,
3939
) -> None:
4040
httpx_mock.add_response(
41-
url=f"{base_url}{org}{tenant}/orchestrator_/odata/Folders?%24filter=DisplayName+eq+%27test-folder-path%27&%24top=1&%24select=Key",
41+
url=f"{base_url}{org}{tenant}/orchestrator_/api/FoldersNavigation/GetFoldersForCurrentUser?searchText=test-folder-path&skip=0&take=20",
4242
status_code=200,
4343
json={
44-
"value": [
44+
"PageItems": [
4545
{
4646
"Key": "test-folder-key",
47+
"FullyQualifiedName": "test-folder-path",
4748
}
4849
]
4950
},
@@ -67,12 +68,13 @@ def test_search(
6768
)
6869

6970
httpx_mock.add_response(
70-
url=f"{base_url}{org}{tenant}/orchestrator_/odata/Folders?%24filter=DisplayName+eq+%27test-folder-path%27&%24top=1&%24select=Key",
71+
url=f"{base_url}{org}{tenant}/orchestrator_/api/FoldersNavigation/GetFoldersForCurrentUser?searchText=test-folder-path&skip=0&take=20",
7172
status_code=200,
7273
json={
73-
"value": [
74+
"PageItems": [
7475
{
7576
"Key": "test-folder-key",
77+
"FullyQualifiedName": "test-folder-path",
7678
}
7779
]
7880
},
@@ -130,12 +132,13 @@ async def test_search_async(
130132
version: str,
131133
) -> None:
132134
httpx_mock.add_response(
133-
url=f"{base_url}{org}{tenant}/orchestrator_/odata/Folders?%24filter=DisplayName+eq+%27test-folder-path%27&%24top=1&%24select=Key",
135+
url=f"{base_url}{org}{tenant}/orchestrator_/api/FoldersNavigation/GetFoldersForCurrentUser?searchText=test-folder-path&skip=0&take=20",
134136
status_code=200,
135137
json={
136-
"value": [
138+
"PageItems": [
137139
{
138140
"Key": "test-folder-key",
141+
"FullyQualifiedName": "test-folder-path",
139142
}
140143
]
141144
},
@@ -159,12 +162,13 @@ async def test_search_async(
159162
)
160163

161164
httpx_mock.add_response(
162-
url=f"{base_url}{org}{tenant}/orchestrator_/odata/Folders?%24filter=DisplayName+eq+%27test-folder-path%27&%24top=1&%24select=Key",
165+
url=f"{base_url}{org}{tenant}/orchestrator_/api/FoldersNavigation/GetFoldersForCurrentUser?searchText=test-folder-path&skip=0&take=20",
163166
status_code=200,
164167
json={
165-
"value": [
168+
"PageItems": [
166169
{
167170
"Key": "test-folder-key",
171+
"FullyQualifiedName": "test-folder-path",
168172
}
169173
]
170174
},
@@ -221,12 +225,13 @@ def test_retrieve(
221225
version: str,
222226
) -> None:
223227
httpx_mock.add_response(
224-
url=f"{base_url}{org}{tenant}/orchestrator_/odata/Folders?%24filter=DisplayName+eq+%27test-folder-path%27&%24top=1&%24select=Key",
228+
url=f"{base_url}{org}{tenant}/orchestrator_/api/FoldersNavigation/GetFoldersForCurrentUser?searchText=test-folder-path&skip=0&take=20",
225229
status_code=200,
226230
json={
227-
"value": [
231+
"PageItems": [
228232
{
229233
"Key": "test-folder-key",
234+
"FullyQualifiedName": "test-folder-path",
230235
}
231236
]
232237
},
@@ -280,17 +285,17 @@ async def test_retrieve_async(
280285
version: str,
281286
) -> None:
282287
httpx_mock.add_response(
283-
url=f"{base_url}{org}{tenant}/orchestrator_/odata/Folders?%24filter=DisplayName+eq+%27test-folder-path%27&%24top=1&%24select=Key",
288+
url=f"{base_url}{org}{tenant}/orchestrator_/api/FoldersNavigation/GetFoldersForCurrentUser?searchText=test-folder-path&skip=0&take=20",
284289
status_code=200,
285290
json={
286-
"value": [
291+
"PageItems": [
287292
{
288293
"Key": "test-folder-key",
294+
"FullyQualifiedName": "test-folder-path",
289295
}
290296
]
291297
},
292298
)
293-
294299
httpx_mock.add_response(
295300
url=f"{base_url}{org}{tenant}/ecs_/v2/indexes?$filter=Name eq 'test-index'&$expand=dataSource",
296301
status_code=200,

0 commit comments

Comments
 (0)