Skip to content

Conversation

@dibahlfi
Copy link
Member

Fixed a bug where a compound session token (containing multiple partition tokens) was sent for single-partition feed range queries. Now, only the relevant partition's session token is sent when querying with a specific feed range reducing unnecessary token data in requests.

Copilot AI review requested due to automatic review settings December 19, 2025 04:00
@dibahlfi dibahlfi requested a review from a team as a code owner December 19, 2025 04:00
Copy link
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 a session token optimization bug where compound session tokens (containing tokens for all partitions) were being sent for single-partition feed range queries. The fix ensures that when querying with a specific feed range, only the relevant partition's session token is sent, reducing unnecessary token data in requests.

Key Changes

  • Added set_session_token_header call within the feed range loop to set partition-specific session tokens
  • Added comprehensive tests for both sync and async clients to verify single partition tokens are sent instead of compound tokens

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py Adds call to set_session_token_header for specific partition within feed range loop
sdk/cosmos/azure-cosmos/azure/cosmos/aio/_cosmos_client_connection_async.py Adds call to set_session_token_header for specific partition within feed range loop (async version)
sdk/cosmos/azure-cosmos/tests/test_session.py Adds test to verify single partition tokens are sent for feed range queries
sdk/cosmos/azure-cosmos/tests/test_session_async.py Adds async test to verify single partition tokens are sent for feed range queries

Copy link
Member

@tvaron3 tvaron3 left a comment

Choose a reason for hiding this comment

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

LGTM but please run live tests

EPK_sub_range = routing_range.Range(range_min=max(single_range.min, feed_range_epk.min),
range_max=min(single_range.max, feed_range_epk.max),
isMinInclusive=True, isMaxInclusive=False)

Copy link
Member

Choose a reason for hiding this comment

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

change log entry?

Copy link
Member

Choose a reason for hiding this comment

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

Changelog should be updated to use 4.15.0b3 given the recent release, would also need an update on _version.py or if another PR is merged in before this then just adding this to the updated changelog.

# Query with single feed range
list(test_container.query_items(
query="SELECT * FROM c",
feed_range=feed_ranges[0],
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use a feed_range overlaps multiple feed ranges?

@simorenoh
Copy link
Member

/azp run python - cosmos - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

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.

6 participants