Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/cosmos/azure-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#### Breaking Changes

#### Bugs Fixed
* 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)

#### Other Changes

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# The MIT License (MIT)
# The MIT License (MIT)
# Copyright (c) 2014 Microsoft Corporation

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

transport = kwargs.pop("transport", None)
self.pipeline_client: PipelineClient[HttpRequest, HttpResponse] = PipelineClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def __init__( # pylint: disable=too-many-statements
]
# after passing in the user_agent into the user agent policy the user_agent is no longer needed
kwargs.pop("user_agent", None)
kwargs.pop("user_agent_overwrite", None)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this user_agent_overwrite keyword in the docstring somewhere?

Also, it would be ideal to link the PR when this new keyword was first added. I wasn't sure where this keyword was used before it was popped here.


transport = kwargs.pop("transport", None)
self.pipeline_client: AsyncPipelineClient[HttpRequest, AsyncHttpResponse] = AsyncPipelineClient(
Expand Down
16 changes: 16 additions & 0 deletions sdk/cosmos/azure-cosmos/tests/test_user_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ def _run_case(use_suffix: bool) -> None:
_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.
"""Regression test: user_agent_overwrite must not leak into the HTTP transport kwargs.
"""
# user_agent + user_agent_overwrite=True at client level
self._check({'user_agent': 'MyApp/1.0', 'user_agent_overwrite': True})
# user_agent + user_agent_overwrite=False at client level
self._check({'user_agent': 'MyApp/1.0', 'user_agent_overwrite': False})
# user_agent_suffix + user_agent_overwrite=True at client level
self._check({'user_agent_suffix': 'MyApp/1.0', 'user_agent_overwrite': True})
# user_agent_suffix + user_agent_overwrite=False at client level
self._check({'user_agent_suffix': 'MyApp/1.0', 'user_agent_overwrite': False})
# user_agent_overwrite=True alone (no custom user_agent string)
self._check({'user_agent_overwrite': True})
# user_agent_overwrite=False alone
self._check({'user_agent_overwrite': False})


if __name__ == '__main__':
unittest.main()
17 changes: 16 additions & 1 deletion sdk/cosmos/azure-cosmos/tests/test_user_agent_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,22 @@ async def _run_case(use_suffix: bool):
await _run_case(False)
await _run_case(True)

async def test_user_agent_overwrite_does_not_leak_async(self):
"""Regression test: user_agent_overwrite must not leak into the HTTP transport kwargs.
"""
# user_agent + user_agent_overwrite=True at client level
await self._check({'user_agent': 'MyApp/1.0', 'user_agent_overwrite': True})
# user_agent + user_agent_overwrite=False at client level
await self._check({'user_agent': 'MyApp/1.0', 'user_agent_overwrite': False})
# user_agent_suffix + user_agent_overwrite=True at client level
await self._check({'user_agent_suffix': 'MyApp/1.0', 'user_agent_overwrite': True})
# user_agent_suffix + user_agent_overwrite=False at client level
await self._check({'user_agent_suffix': 'MyApp/1.0', 'user_agent_overwrite': False})
# user_agent_overwrite=True alone (no custom user_agent string)
await self._check({'user_agent_overwrite': True})
# user_agent_overwrite=False alone
await self._check({'user_agent_overwrite': False})


if __name__ == "__main__":
unittest.main()

Loading