Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

dibahlfi
Copy link
Contributor

@dibahlfi dibahlfi commented Sep 11, 2025

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.

@Copilot Copilot AI review requested due to automatic review settings September 11, 2025 16:41
@dibahlfi dibahlfi requested a review from a team as a code owner September 11, 2025 16:41
Copy link
Contributor

@Copilot 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 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

@simorenoh
Copy link
Member

/azp run python - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@allenkim0129 allenkim0129 left a comment

Choose a reason for hiding this comment

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

LGTM

@dibahlfi dibahlfi merged commit f6ac36d into main Sep 11, 2025
21 checks passed
@dibahlfi dibahlfi deleted the users/dibahl/client-session-propagation branch September 11, 2025 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants