fix: TypeError - requests.Session.request() got an unexpected keyword argument 'user_agent_overwrite'#45653
fix: TypeError - requests.Session.request() got an unexpected keyword argument 'user_agent_overwrite'#45653
Conversation
…ser_agent_overwrite
|
/azp run python - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
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_overwritefrom client-connectionkwargsin 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, anduser_agent_overwriteto 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): |
There was a problem hiding this comment.
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.
| def test_user_agent_overwrite_does_not_leak_sync(self): | |
| def test_user_agent_overwrite_does_not_leak(self): |
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'