Return CosmosItemPaged from query_items_change_feed for thread-safe headers#47947
Open
andrewmathew1 wants to merge 1 commit into
Open
Return CosmosItemPaged from query_items_change_feed for thread-safe headers#47947andrewmathew1 wants to merge 1 commit into
andrewmathew1 wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Cosmos DB change feed query paging behavior so query_items_change_feed() returns the Cosmos-specific paging types (CosmosItemPaged / CosmosAsyncItemPaged), allowing callers to retrieve per-page and last-page response headers (notably the change feed continuation token via etag) without relying on the shared, non-thread-safe container.client_connection.last_response_headers.
Changes:
- Changed
query_items_change_feed()(sync/async) return types toCosmosItemPaged/CosmosAsyncItemPagedand threaded a per-callresponse_headers_listinto the paging pipeline. - Updated client-connection change feed methods to construct and pass a shared
response_headers_listso each page fetch appends a snapshot of response headers. - Added sync/async tests validating
etagis exposed viaget_last_response_headers()(including empty change feed behavior), and documented the feature inCHANGELOG.md.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/cosmos/azure-cosmos/azure/cosmos/container.py | Updates query_items_change_feed() type hints/doc rtype to CosmosItemPaged. |
| sdk/cosmos/azure-cosmos/azure/cosmos/aio/_container.py | Updates async query_items_change_feed() type hints/doc rtype to CosmosAsyncItemPaged. |
| sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py | Returns CosmosItemPaged for change feed queries and wires a per-call response_headers_list into __QueryFeed. |
| sdk/cosmos/azure-cosmos/azure/cosmos/aio/_cosmos_client_connection_async.py | Returns CosmosAsyncItemPaged for change feed queries and wires a per-call response_headers_list into async __QueryFeed. |
| sdk/cosmos/azure-cosmos/tests/test_query_response_headers.py | Adds coverage for sync change feed header exposure (etag) via the public paging API. |
| sdk/cosmos/azure-cosmos/tests/test_query_response_headers_async.py | Adds coverage for async change feed header exposure (etag) via the public paging API. |
| sdk/cosmos/azure-cosmos/CHANGELOG.md | Documents the new header access behavior for change feed paging. |
Comment on lines
+1229
to
1232
| ) -> CosmosItemPaged: | ||
| """Queries documents change feed in a collection. | ||
|
|
||
| :param str collection_link: The link to the document collection. |
Comment on lines
+1258
to
1261
| ) -> CosmosItemPaged: | ||
| """Queries change feed of a resource in a collection. | ||
|
|
||
| :param str collection_link: The link to the document collection. |
Comment on lines
+2445
to
2448
| ) -> CosmosAsyncItemPaged: | ||
| """Queries documents change feed in a collection. | ||
|
|
||
| :param str collection_link: The link to the document collection. |
Comment on lines
+2475
to
2478
| ) -> CosmosAsyncItemPaged: | ||
| """Queries change feed of a resource in a collection. | ||
|
|
||
| :param str collection_link: The link to the document collection. |
query_items_change_feed() now returns CosmosItemPaged (sync) / CosmosAsyncItemPaged (async), matching query_items(). This exposes the thread-safe public get_response_headers() API so users can read the change feed continuation token (etag) from the latest page instead of the non-thread-safe internal client_connection.last_response_headers. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
52557a1 to
46d1e37
Compare
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.
Description
query_items_change_feed() now returns CosmosItemPaged (sync) and CosmosAsyncItemPaged (async) instead of a plain ItemPaged/AsyncItemPaged. This exposes get_response_headers() and get_last_response_headers(), giving users a thread-safe, public way to read the change feed continuation token (etag) via response.get_last_response_headers()['etag'] instead of relying on the non-thread-safe
container.client_connection.last_response_headers.
The connection methods build a per-call response_headers_list that is threaded into __QueryFeed (which appends each page's headers) and passed to the paged object, mirroring the existing query_items pattern.