Fix silent data truncation in client.query.sql() — add @odata.nextLink pagination (#157)#159
Open
Fix silent data truncation in client.query.sql() — add @odata.nextLink pagination (#157)#159
Conversation
Add unit tests for batch serialization, OData key formatting, SQL parsing, and batch operations - Implemented unit tests for internal batch multipart serialization and response parsing in `test_batch_serialization.py`. - Added tests for `_ODataClient._format_key` functionality in `test_format_key.py`. - Enhanced SQL parsing tests in `test_sql_parse.py` to cover URL encoding scenarios. - Created comprehensive tests for batch operations, including record and table operations, in `test_batch_operations.py`.
… batch processing components
…el reorganization - Keep both client.files and client.batch namespaces - Accept origin/main's _list_entities with filter/select parameters - Fix imports: models.metadata was reorganized into relationship.py + labels.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…into the body; add unit tests for _ODataClient._build_upsert_multiple validation
…hance related tests
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes silent result truncation in client.query.sql() by adding OData nextLink pagination to the underlying _ODataClient._query_sql implementation, plus safeguards to prevent infinite pagination loops (including a pagingcookie-based guard for a known Dataverse SQL endpoint issue).
Changes:
- Implement multi-page SQL query result fetching by following
@odata.nextLink/odata.nextLinkuntil exhausted. - Add
_extract_pagingcookie()helper and “stuck pagingcookie” detection withRuntimeWarningto prevent infinite loops. - Add unit tests covering pagination behavior and pagingcookie extraction; update changelog entry for the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/PowerPlatform/Dataverse/data/_odata.py |
Adds _extract_pagingcookie() and extends _query_sql() to follow @odata.nextLink with loop guards and warnings. |
tests/unit/data/test_sql_parse.py |
Adds pagination tests for _query_sql and unit tests for _extract_pagingcookie. |
CHANGELOG.md |
Documents the fix under a new [Unreleased] section. |
README.md |
Minor markdown whitespace adjustment near the batch example section. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
abelmilash-msft
previously approved these changes
Apr 9, 2026
…s and update tests
…57_fix_sql_truncation
abelmilash-msft
approved these changes
Apr 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
client.query.sql() silently returned only the first 5,000 rows regardless of result set size. The method now follows @odata.nextLink until all pages are exhausted.
Added _extract_pagingcookie() helper to detect a confirmed server-side bug where the Dataverse SQL endpoint returns successive @odata.nextLink responses with pagenumber incrementing but the pagingcookie GUIDs (keyset cursor) never advancing — causing an infinite pagination loop. The SDK now detects and breaks out of this condition and emits a RuntimeWarning.
Pagination is guarded against three failure modes: exact URL cycles, stuck pagingcookie (server bug), and failed or non-JSON next-page responses. All three emit RuntimeWarning with the partial row count and actionable guidance.