Cosmos: change query response headers to only return latest page#47172
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR changes Cosmos query pagination header capture from retaining all page headers to exposing only the latest page’s headers, reducing memory growth for large paginated queries.
Changes:
- Replaces per-page header lists with a shared latest-header
CaseInsensitiveDict. - Removes
get_last_response_headers()and updates tests for latest-page semantics. - Adds a breaking-change changelog entry for the API behavior change.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_responses.py |
Updates paged response wrappers to return latest headers only. |
sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py |
Updates sync query header capture to overwrite latest headers. |
sdk/cosmos/azure-cosmos/azure/cosmos/aio/_cosmos_client_connection_async.py |
Updates async query header capture to overwrite latest headers. |
sdk/cosmos/azure-cosmos/tests/test_query_response_headers.py |
Adjusts sync tests for latest-page header behavior. |
sdk/cosmos/azure-cosmos/tests/test_query_response_headers_async.py |
Adjusts async tests for latest-page header behavior. |
sdk/cosmos/azure-cosmos/CHANGELOG.md |
Documents the breaking change. |
- Add None guard on kwargs.pop('response_headers') in CosmosItemPaged
and CosmosAsyncItemPaged constructors
- Empty result tests: assert x-ms-request-charge presence instead of
tautological assertIsNotNone
- By-page tests: loosen exact page count assertions since
max_item_count is a hint, not a contract
- Copies tests: add assertIsNot identity check
- Thread-safety tests: add cross-iterable isolation assertion
(assertIsNot on headers from different queries)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
tvaron3
approved these changes
May 27, 2026
Member
tvaron3
left a comment
There was a problem hiding this comment.
LGTM, with friendly reminder to run live tests as well
…subclass Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
|
/azp run python - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
|
LGTM. |
kushagraThapar
approved these changes
May 27, 2026
Member
Author
Co-authored-by: Kushagra Thapar <kuthapar@microsoft.com>
kushagraThapar
approved these changes
May 28, 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.

Simplify query response headers to last-page-only
Replaces the unbounded list[CaseInsensitiveDict] accumulated per page with a single CaseInsensitiveDict that is overwritten on each page fetch. This avoids memory growth for queries spanning thousands of pages.
Changes