Skip to content

Commit

Permalink
chore: re-add user agent to client
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwotherspoon committed Jan 15, 2024
1 parent 60c145e commit 9e444b1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
1 change: 1 addition & 0 deletions google/cloud/alloydb/connector/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(
# asyncpg does not currently support using metadata exchange
# only use metadata exchange for pg8000 driver
self._use_metadata = True if driver == "pg8000" else False
self._user_agent = user_agent

async def _get_metadata(
self,
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/alloydb/connector/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def metadata_exchange(

# form metadata exchange request
req = connectorspb.MetadataExchangeRequest(
user_agent=f"{self._client._user_agent}+{driver}", # type: ignore
user_agent=f"{self._client._user_agent}", # type: ignore
auth_type=auth_type,
oauth2_token=self._credentials.token,
)
Expand Down
10 changes: 2 additions & 8 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,9 @@ async def test_AlloyDBClient_user_agent(
"www.test-endpoint.com", "my-quota-project", credentials, driver=driver
)
if driver is None:
assert (
client._client.headers["User-Agent"]
== f"alloydb-python-connector/{version}"
)
assert client._user_agent == f"alloydb-python-connector/{version}"
else:
assert (
client._client.headers["User-Agent"]
== f"alloydb-python-connector/{version}+{driver}"
)
assert client._user_agent == f"alloydb-python-connector/{version}+{driver}"
# close client
await client.close()

Expand Down

0 comments on commit 9e444b1

Please sign in to comment.