Skip to content

Commit 010a8b7

Browse files
yashwagle1claudeAAgnihotry
authored
fix(automation-ops): handle empty deployed-policy response (#1642)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: AAgnihotry <95259907+AAgnihotry@users.noreply.github.com>
1 parent 4de530c commit 010a8b7

5 files changed

Lines changed: 49 additions & 7 deletions

File tree

packages/uipath-platform/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-platform"
3-
version = "0.1.53"
3+
version = "0.1.54"
44
description = "HTTP client library for programmatic access to UiPath Platform"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"

packages/uipath-platform/src/uipath/platform/automation_ops/_automation_ops_service.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def get_deployed_policy(self) -> dict[str, Any]:
3030
"""Retrieve the deployed policy.
3131
3232
Returns:
33-
The deployed policy response as a dictionary.
33+
The deployed policy response as a dictionary. Returns an empty
34+
dict when no policy is deployed (empty 200 response body).
3435
"""
3536
spec = self._deployed_policy_spec()
3637
response = self.request(
@@ -39,14 +40,17 @@ def get_deployed_policy(self) -> dict[str, Any]:
3940
headers=spec.headers,
4041
scoped="tenant",
4142
)
43+
if not response.content:
44+
return {}
4245
return response.json()
4346

4447
@traced(name="automation_ops_get_deployed_policy", run_type="uipath")
4548
async def get_deployed_policy_async(self) -> dict[str, Any]:
4649
"""Retrieve the deployed policy (async).
4750
4851
Returns:
49-
The deployed policy response as a dictionary.
52+
The deployed policy response as a dictionary. Returns an empty
53+
dict when no policy is deployed (empty 200 response body).
5054
"""
5155
spec = self._deployed_policy_spec()
5256
response = await self.request_async(
@@ -55,6 +59,8 @@ async def get_deployed_policy_async(self) -> dict[str, Any]:
5559
headers=spec.headers,
5660
scoped="tenant",
5761
)
62+
if not response.content:
63+
return {}
5864
return response.json()
5965

6066
def _deployed_policy_spec(self) -> RequestSpec:

packages/uipath-platform/tests/services/test_automation_ops_service.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ def test_returns_policy_dict(
4949

5050
assert result == expected_policy
5151

52+
def test_returns_empty_dict_when_no_policy_deployed(
53+
self,
54+
httpx_mock: HTTPXMock,
55+
service: AutomationOpsService,
56+
base_url: str,
57+
org: str,
58+
tenant: str,
59+
) -> None:
60+
httpx_mock.add_response(
61+
url=f"{base_url}{org}{tenant}/agenthub_/api/policies/deployed-policy",
62+
status_code=200,
63+
content=b"",
64+
)
65+
66+
result = service.get_deployed_policy()
67+
68+
assert result == {}
69+
5270
def test_uses_post_method(
5371
self,
5472
httpx_mock: HTTPXMock,
@@ -102,6 +120,24 @@ async def test_returns_policy_dict(
102120

103121
assert result == expected_policy
104122

123+
async def test_returns_empty_dict_when_no_policy_deployed(
124+
self,
125+
httpx_mock: HTTPXMock,
126+
service: AutomationOpsService,
127+
base_url: str,
128+
org: str,
129+
tenant: str,
130+
) -> None:
131+
httpx_mock.add_response(
132+
url=f"{base_url}{org}{tenant}/agenthub_/api/policies/deployed-policy",
133+
status_code=200,
134+
content=b"",
135+
)
136+
137+
result = await service.get_deployed_policy_async()
138+
139+
assert result == {}
140+
105141
async def test_url_is_tenant_scoped(
106142
self,
107143
httpx_mock: HTTPXMock,

packages/uipath-platform/uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/uipath/uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)