Skip to content

Commit 30f1ea3

Browse files
dibahlfisimorenoh
andauthored
fix: TypeError - requests.Session.request() got an unexpected keyword argument 'user_agent_overwrite' (#45653)
* fix - TypeError: Session.request() got an unexpected word argument 'user_agent_overwrite * fix - updating changelog --------- Co-authored-by: Simon Moreno <30335873+simorenoh@users.noreply.github.com>
1 parent 985d8a1 commit 30f1ea3

5 files changed

Lines changed: 36 additions & 2 deletions

File tree

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#### Breaking Changes
1111

1212
#### Bugs Fixed
13+
* Fixed regression where `user_agent_overwrite` kwarg was not cleaned up properly, causing `TypeError` crash on sync client construction. See [PR 45653](https://github.com/Azure/azure-sdk-for-python/pull/45653)
1314

1415
#### Other Changes
1516

sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# The MIT License (MIT)
1+
# The MIT License (MIT)
22
# Copyright (c) 2014 Microsoft Corporation
33

44
# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -248,6 +248,7 @@ def __init__( # pylint: disable=too-many-statements
248248
]
249249
# after passing in the user_agent into the user agent policy the user_agent is no longer needed
250250
kwargs.pop("user_agent", None)
251+
kwargs.pop("user_agent_overwrite", None)
251252

252253
transport = kwargs.pop("transport", None)
253254
self.pipeline_client: PipelineClient[HttpRequest, HttpResponse] = PipelineClient(

sdk/cosmos/azure-cosmos/azure/cosmos/aio/_cosmos_client_connection_async.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ def __init__( # pylint: disable=too-many-statements
245245
]
246246
# after passing in the user_agent into the user agent policy the user_agent is no longer needed
247247
kwargs.pop("user_agent", None)
248+
kwargs.pop("user_agent_overwrite", None)
248249

249250
transport = kwargs.pop("transport", None)
250251
self.pipeline_client: AsyncPipelineClient[HttpRequest, AsyncHttpResponse] = AsyncPipelineClient(

sdk/cosmos/azure-cosmos/tests/test_user_agent.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,22 @@ def _run_case(use_suffix: bool) -> None:
9595
_run_case(False) # prefix scenario
9696
_run_case(True) # suffix scenario
9797

98+
def test_user_agent_overwrite_does_not_leak_sync(self):
99+
"""Regression test: user_agent_overwrite must not leak into the HTTP transport kwargs.
100+
"""
101+
# user_agent + user_agent_overwrite=True at client level
102+
self._check({'user_agent': 'MyApp/1.0', 'user_agent_overwrite': True})
103+
# user_agent + user_agent_overwrite=False at client level
104+
self._check({'user_agent': 'MyApp/1.0', 'user_agent_overwrite': False})
105+
# user_agent_suffix + user_agent_overwrite=True at client level
106+
self._check({'user_agent_suffix': 'MyApp/1.0', 'user_agent_overwrite': True})
107+
# user_agent_suffix + user_agent_overwrite=False at client level
108+
self._check({'user_agent_suffix': 'MyApp/1.0', 'user_agent_overwrite': False})
109+
# user_agent_overwrite=True alone (no custom user_agent string)
110+
self._check({'user_agent_overwrite': True})
111+
# user_agent_overwrite=False alone
112+
self._check({'user_agent_overwrite': False})
113+
98114

99115
if __name__ == '__main__':
100116
unittest.main()

sdk/cosmos/azure-cosmos/tests/test_user_agent_async.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,22 @@ async def _run_case(use_suffix: bool):
8484
await _run_case(False)
8585
await _run_case(True)
8686

87+
async def test_user_agent_overwrite_does_not_leak_async(self):
88+
"""Regression test: user_agent_overwrite must not leak into the HTTP transport kwargs.
89+
"""
90+
# user_agent + user_agent_overwrite=True at client level
91+
await self._check({'user_agent': 'MyApp/1.0', 'user_agent_overwrite': True})
92+
# user_agent + user_agent_overwrite=False at client level
93+
await self._check({'user_agent': 'MyApp/1.0', 'user_agent_overwrite': False})
94+
# user_agent_suffix + user_agent_overwrite=True at client level
95+
await self._check({'user_agent_suffix': 'MyApp/1.0', 'user_agent_overwrite': True})
96+
# user_agent_suffix + user_agent_overwrite=False at client level
97+
await self._check({'user_agent_suffix': 'MyApp/1.0', 'user_agent_overwrite': False})
98+
# user_agent_overwrite=True alone (no custom user_agent string)
99+
await self._check({'user_agent_overwrite': True})
100+
# user_agent_overwrite=False alone
101+
await self._check({'user_agent_overwrite': False})
102+
87103

88104
if __name__ == "__main__":
89105
unittest.main()
90-

0 commit comments

Comments
 (0)