Skip to content

Fix silent data truncation in client.query.sql() — add @odata.nextLink pagination (#157)#159

Open
sagebree wants to merge 17 commits intomainfrom
users/sagebree/issue157_fix_sql_truncation
Open

Fix silent data truncation in client.query.sql() — add @odata.nextLink pagination (#157)#159
sagebree wants to merge 17 commits intomainfrom
users/sagebree/issue157_fix_sql_truncation

Conversation

@sagebree
Copy link
Copy Markdown
Contributor

@sagebree sagebree commented Apr 9, 2026

  • 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.

Samson Gebre and others added 14 commits February 25, 2026 15:31
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`.
…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
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sagebree sagebree requested a review from a team as a code owner April 9, 2026 02:37
Copilot AI review requested due to automatic review settings April 9, 2026 02:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.nextLink until exhausted.
  • Add _extract_pagingcookie() helper and “stuck pagingcookie” detection with RuntimeWarning to 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
abelmilash-msft previously approved these changes Apr 9, 2026
@sagebree sagebree requested a review from abelmilash-msft April 9, 2026 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants