Closed
Conversation
Collaborator
API Change CheckAPIView identified API level changes in this PR and created the following API reviews |
Collaborator
|
API change check APIView has identified API level changes in this PR and created following API reviews. |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors how session tokens are managed and sent for Azure Cosmos DB operations, introducing targeted token sending, caching improvements, and automatic refresh on partition splits.
- Only relevant requests (reads, batches, multi-write scenarios) now include session tokens.
- SessionContainer API expanded to handle partition key and routing info, with both sync/async support.
- Header-building logic moved to
_base.set_session_token_header(_async)and propagated throughout client connection flows.
Reviewed Changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/cosmos/azure-cosmos/azure/cosmos/_session.py | Overhauled SessionContainer: changed get/set signatures and logic |
| sdk/cosmos/azure-cosmos/azure/cosmos/_base.py | Introduced set_session_token_header(_async) helper, removed old logic |
| sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py | Added session header injection in sync client methods |
| sdk/cosmos/azure-cosmos/azure/cosmos/aio/_cosmos_client_connection_async.py | Added session header injection in async client methods |
| sdk/cosmos/azure-cosmos/tests/test_session_container.py | Deleted legacy session-container tests |
Comments suppressed due to low confidence (3)
sdk/cosmos/azure-cosmos/azure/cosmos/_session.py:80
- The variable
collection_nameis not defined in the non-name-based branch, leading to an UnboundLocalError. Ensurecollection_nameis initialized in both branches before use.
if collection_rid in self.rid_to_session_token and collection_name in container_properties_cache:
sdk/cosmos/azure-cosmos/azure/cosmos/_session.py:135
- In the async
get_session_token_async,collection_nameis also undefined in the non-name-based path. Definecollection_nameconsistently in both branches.
if collection_rid in self.rid_to_session_token and collection_name in container_properties_cache:
Member
Author
|
/azp run python - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
Author
|
/azp run python - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
tvaron3
reviewed
Jun 10, 2025
sdk/cosmos/azure-cosmos/tests/test_latest_session_token_async.py
Outdated
Show resolved
Hide resolved
Member
|
/azp run python - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
5 tasks
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.
This PR initially aimed at closing several gaps in the session token handling logic of the Python SDK's session container, specifically sending the entire compound session token for a container for every request, but as a result of this has now grown beyond that in scope. This PR now also addresses and closes the following issues:
Pending items
Current state
The Python SDK currently does several things that should be improved upon for session consistency behaviors:
Changes introduced
In order to address the above issues, the following changes have been made:
Caveats
We currently only initiate the session container within a client if the user properly initializes their client. While this is not a problem for the sync client, it means that users that are not directly initializing their asynchronous clients as outlined in our README will not be able to leverage the session container, and will have to implement their own session token handling logic to achieve session consistency.