Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug where manually provided session tokens in options are ignored when client-side session management is disabled. The fix ensures that explicitly provided session tokens take precedence over automatic session management.
- Restructures session token handling logic to prioritize manual overrides
- Adds comprehensive test coverage for the manual session token override scenario
- Updates both synchronous and asynchronous code paths consistently
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| sdk/cosmos/azure-cosmos/azure/cosmos/_base.py | Refactors session token logic to check manual override first, then fallback to automatic session management |
| sdk/cosmos/azure-cosmos/tests/test_session.py | Adds test case for manual session token override with disabled client-side session management |
| sdk/cosmos/azure-cosmos/tests/test_session_async.py | Adds async version of the manual session token override test case |
Member
|
/azp run python - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
bambriz
reviewed
Sep 11, 2025
simorenoh
approved these changes
Sep 11, 2025
simorenoh
approved these changes
Sep 11, 2025
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 is to fix a bug where if a session token is explicitly provided in options(allowing manual override) it doesn't take effect when client-side session management is disabled.
Fix involve removing the "cosmos_client_connection.session is not None" check from _is_session_token_request method
The _is_session_token_request function is now solely responsible for determining if the type of request is eligible for a session token.
In set_session_token_header, the code first calls the modified _is_session_token_request. If it returns True, the code then enters a block where it checks for a manually provided sessionToken. Because the check for the session object is gone from the initial function, this block is now reachable even when cosmos_client_connection.session is None.
The check for cosmos_client_connection.session still exists in the else block within set_session_token_header. This ensures that the automatic session token logic only runs when client-side session management is actually enabled.