Skip to content

fix: TypeError - requests.Session.request() got an unexpected keyword argument 'user_agent_overwrite'#45653

Open
dibahlfi wants to merge 2 commits intomainfrom
users/dibahl/user-agent-fix
Open

fix: TypeError - requests.Session.request() got an unexpected keyword argument 'user_agent_overwrite'#45653
dibahlfi wants to merge 2 commits intomainfrom
users/dibahl/user-agent-fix

Conversation

@dibahlfi
Copy link
Member

This PR fixes a regression introduced with v4.15.0b1 release where the user_agent_overwrite kwarg was not popped from kwargs after being consumed by CosmosUserAgentPolicy.init(). This caused the kwarg to leak through _GetDatabaseAccount(**kwargs) into the HTTP transport layer, resulting in:
TypeError: requests.Session.request() got an unexpected keyword argument 'user_agent_overwrite'

@dibahlfi dibahlfi requested a review from a team as a code owner March 11, 2026 23:34
Copilot AI review requested due to automatic review settings March 11, 2026 23:34
@dibahlfi
Copy link
Member Author

/azp run python - cosmos - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

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

Fixes a regression in azure-cosmos (introduced in v4.15.0b1) where user_agent_overwrite was unintentionally left in the kwargs passed down into the transport layer, causing requests.Session.request() to raise a TypeError.

Changes:

  • Pop user_agent_overwrite from client-connection kwargs in both sync and async Cosmos client connection implementations to prevent it from leaking into lower layers.
  • Add sync + async regression tests that exercise combinations of user_agent, user_agent_suffix, and user_agent_overwrite to ensure no transport-level kwarg leakage.

Reviewed changes

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

File Description
sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py Removes user_agent_overwrite from kwargs after it has been consumed for policy setup (sync path).
sdk/cosmos/azure-cosmos/azure/cosmos/aio/_cosmos_client_connection_async.py Removes user_agent_overwrite from kwargs after it has been consumed for policy setup (async path).
sdk/cosmos/azure-cosmos/tests/test_user_agent.py Adds a sync regression test to validate user_agent_overwrite doesn’t leak into transport kwargs.
sdk/cosmos/azure-cosmos/tests/test_user_agent_async.py Adds an async regression test to validate user_agent_overwrite doesn’t leak into transport kwargs.

_run_case(False) # prefix scenario
_run_case(True) # suffix scenario

def test_user_agent_overwrite_does_not_leak_sync(self):
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

Test method name includes a _sync suffix, but other tests in this (sync) test module don’t use _sync in their names (e.g., test_user_agent_special_characters, test_user_agent_with_features). Consider renaming this test to match the existing naming pattern (e.g., drop the _sync suffix) to keep test discovery/naming consistent.

Suggested change
def test_user_agent_overwrite_does_not_leak_sync(self):
def test_user_agent_overwrite_does_not_leak(self):

Copilot uses AI. Check for mistakes.
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.

3 participants