Skip to content

Return CosmosItemPaged from query_items_change_feed for thread-safe headers#47947

Open
andrewmathew1 wants to merge 1 commit into
Azure:mainfrom
andrewmathew1:users/andrewmathew1/feedrangeapigap
Open

Return CosmosItemPaged from query_items_change_feed for thread-safe headers#47947
andrewmathew1 wants to merge 1 commit into
Azure:mainfrom
andrewmathew1:users/andrewmathew1/feedrangeapigap

Conversation

@andrewmathew1

Copy link
Copy Markdown
Contributor

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.

Copilot AI review requested due to automatic review settings July 8, 2026 15:27
@andrewmathew1 andrewmathew1 requested a review from a team as a code owner July 8, 2026 15:27
@github-actions github-actions Bot added the Cosmos label Jul 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 to CosmosItemPaged / CosmosAsyncItemPaged and threaded a per-call response_headers_list into the paging pipeline.
  • Updated client-connection change feed methods to construct and pass a shared response_headers_list so each page fetch appends a snapshot of response headers.
  • Added sync/async tests validating etag is exposed via get_last_response_headers() (including empty change feed behavior), and documented the feature in CHANGELOG.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>
@andrewmathew1 andrewmathew1 force-pushed the users/andrewmathew1/feedrangeapigap branch from 52557a1 to 46d1e37 Compare July 8, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants