Repository navigation
Respect SQL row limits during pagination - #211
Open
Sylvester Kaczmarek (sylvesterkaczmarek) wants to merge 2 commits into
Open
Sylvester Kaczmarek (sylvesterkaczmarek) wants to merge 2 commits into
Sylvester Kaczmarek (sylvesterkaczmarek) wants to merge 2 commits into
Conversation
Sylvester Kaczmarek (sylvesterkaczmarek)
marked this pull request as ready for review
November 27, 2026 22:50
Sylvester Kaczmarek (sylvesterkaczmarek)
requested a review
from a team
as a code owner
November 27, 2026 22:50
Copilot started reviewing on behalf of
Sylvester Kaczmarek (sylvesterkaczmarek)
November 27, 2026 22:51
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The parser fails to recognize valid parenthesized TOP limits adjacent to projections, causing sync and async clients to follow nextLink and return more rows than requested.
1 open issue
What changed in this PR
Addresses #210 by enforcing SQL row limits across paginated results in both synchronous and asynchronous Dataverse clients.
Changes:
- Adds a shared reader for integer-literal
TOPandOFFSET ... FETCHlimits, leaving unsupported or ambiguous forms to the server. - Stops pagination when the limit is reached and trims excess rows without applying offsets twice.
- Adds regression coverage for sync/async behavior, parsing safeguards, and pagination edge cases.
| File | Description |
|---|---|
tests/unit/data/test_sql_row_limits.py |
Adds shared parsing and sync/async pagination regressions. |
src/PowerPlatform/Dataverse/data/_odata.py |
Enforces row limits during synchronous SQL pagination. |
src/PowerPlatform/Dataverse/data/_odata_base.py |
Adds shared SQL row-limit detection. |
src/PowerPlatform/Dataverse/aio/data/_async_odata.py |
Applies equivalent limits to asynchronous SQL pagination. |
Review effort: Balanced
| re.DOTALL, | ||
| ) | ||
| _SQL_TOP_LIMIT_RE = re.compile( | ||
| r"^\s*SELECT\s+(?:DISTINCT\s+|ALL\s+)?TOP\b\s*(?:\(\s*([0-9]+)\s*\)|([0-9]+))(?=\s)", |
There was a problem hiding this comment.
Fixed in 0e55710. Parenthesized integer TOP now accepts an adjacent projection; the unparenthesized form still requires whitespace. Both clients are covered, including the PERCENT and WITH TIES exclusions. All 71 focused tests, Black and Ruff passed.
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.

Fixes #210.
Summary
Respect integer-literal
TOPandOFFSET ... FETCHrow limits across the complete SQL result in both synchronous and asynchronous clients. Stop requesting pages as soon as the requested number of valid rows is available, trimming an oversized first or final page. Offset handling remains server-side, so the client does not skip rows twice.Use one shared, conservative limit reader for the supported SELECT subset. It ignores quoted values/identifiers and comments, and leaves percentage limits,
WITH TIES, expressions, parameters and ambiguous nested comments to the server. The query text and existing validation are unchanged. Unbounded queries retain pagination and its existing cycle/error guards.TOP 0retains the initial request and returns no rows.Validation
On Python 3.12:
HTTP transport and response pages are mocked. No credentials, live Dataverse tenant or integration endpoint was used, and no public method signature or dependency declaration changes.
Pagination follow-up
Parenthesized TOP counts can be followed immediately by a projection, while unparenthesized counts still require a token separator. Added adjacent bracketed and unquoted projection cases, percentage and WITH TIES exclusions, and both synchronous and asynchronous stopping tests.
Merged main 5d6f358 in signed commit 0e55710. Python 3.12: the focused row-limit suite passed all 71 tests. Black and Ruff checks for the test file passed, as did the diff check. The earlier full-suite result is from the previous revision; a full rerun and hosted CI remain outstanding.