Skip to content

Commit bd74d02

Browse files
Abel Milashclaude
andcommitted
Align async fetchxml JSON parsing with sync pattern
Replace broad try/except around r.json() with hasattr guard, matching the sync FetchXmlQuery pattern. Remove the now-obsolete test that verified the exception-swallowing behavior. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 58fe82e commit bd74d02

2 files changed

Lines changed: 1 addition & 15 deletions

File tree

src/PowerPlatform/Dataverse/aio/models/async_fetchxml_query.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,7 @@ async def execute_pages(self) -> AsyncIterator[QueryResult]:
9999
headers={"Prefer": _PREFER_HEADER},
100100
params={"fetchXml": current_xml},
101101
)
102-
try:
103-
data = r.json()
104-
except Exception:
105-
data = {}
102+
data = r.json() if hasattr(r, "json") else {}
106103

107104
items = data.get("value") if isinstance(data, dict) else None
108105
page_records: List[Record] = []

tests/unit/aio/test_async_query.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -500,17 +500,6 @@ async def test_execute_multi_page_no_cookie_simple_paging(self, async_client, mo
500500
assert len(result) == 2
501501
assert any("simple paging" in str(warning.message) for warning in w)
502502

503-
async def test_execute_json_parse_error_yields_empty_page(self, async_client, mock_od):
504-
"""execute() yields an empty page when the response body cannot be parsed as JSON."""
505-
mock_od._entity_set_from_schema_name = AsyncMock(return_value="accounts")
506-
507-
resp = MagicMock()
508-
resp.json = MagicMock(side_effect=Exception("invalid json"))
509-
mock_od._request = AsyncMock(return_value=resp)
510-
511-
result = await async_client.query.fetchxml(_SIMPLE_FETCHXML).execute()
512-
assert len(result) == 0
513-
514503
async def test_execute_raises_on_max_pages_exceeded(self, async_client, mock_od):
515504
"""execute() raises ValidationError when paging exceeds the maximum page limit."""
516505
import urllib.parse

0 commit comments

Comments
 (0)