-
Notifications
You must be signed in to change notification settings - Fork 3k
[Cosmos] Session container fixes #40366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
API Change CheckAPIView identified API level changes in this PR and created the following API reviews |
API change check APIView has identified API level changes in this PR and created following API reviews. |
There was a problem hiding this 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 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_name
is not defined in the non-name-based branch, leading to an UnboundLocalError. Ensurecollection_name
is 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_name
is also undefined in the non-name-based path. Definecollection_name
consistently in both branches.
if collection_rid in self.rid_to_session_token and collection_name in container_properties_cache:
/azp run python - cosmos - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run python - cosmos - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run python - cosmos - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run python - cosmos - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
sdk/cosmos/azure-cosmos/tests/test_latest_session_token_async.py
Outdated
Show resolved
Hide resolved
/azp run python - cosmos - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
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.