Skip to content

Commit 785c044

Browse files
chore: include bigquery-magics version number in the user agent (#45)
* chore: include bigquery-magics version number in the user agent * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Import version from bigquery_magics.version package to avoid circular dependency. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 85f00ad commit 785c044

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

packages/bigquery-magics/bigquery_magics/bigquery.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,14 @@
104104
import bigquery_magics._versions_helpers
105105
import bigquery_magics.config
106106
import bigquery_magics.line_arg_parser.exceptions
107+
import bigquery_magics.version
107108

108109
try:
109110
from google.cloud import bigquery_storage # type: ignore
110111
except ImportError:
111112
bigquery_storage = None
112113

113-
IPYTHON_USER_AGENT = "ipython-{}".format(IPython.__version__)
114+
USER_AGENT = f"ipython-{IPython.__version__} bigquery-magics/{bigquery_magics.version.__version__}"
114115
context = bigquery_magics.config.context
115116

116117

@@ -418,7 +419,7 @@ def _cell_magic(line, query):
418419
project=project,
419420
credentials=context.credentials,
420421
default_query_job_config=context.default_query_job_config,
421-
client_info=client_info.ClientInfo(user_agent=IPYTHON_USER_AGENT),
422+
client_info=client_info.ClientInfo(user_agent=USER_AGENT),
422423
client_options=bigquery_client_options,
423424
location=location,
424425
)
@@ -633,7 +634,7 @@ def _make_bqstorage_client(client, use_bqstorage_api, client_options):
633634

634635
return client._ensure_bqstorage_client(
635636
client_options=client_options,
636-
client_info=gapic_client_info.ClientInfo(user_agent=IPYTHON_USER_AGENT),
637+
client_info=gapic_client_info.ClientInfo(user_agent=USER_AGENT),
637638
)
638639

639640

packages/bigquery-magics/tests/unit/test_bigquery.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,10 @@ def test_bigquery_magic_default_connection_user_agent():
474474

475475
client_info_arg = conn.call_args[1].get("client_info")
476476
assert client_info_arg is not None
477-
assert client_info_arg.user_agent == "ipython-" + IPython.__version__
477+
assert (
478+
client_info_arg.user_agent
479+
== f"ipython-{IPython.__version__} bigquery-magics/{bigquery_magics.__version__}"
480+
)
478481

479482

480483
@pytest.mark.usefixtures("ipython_interactive")
@@ -615,7 +618,10 @@ def warning_match(warning):
615618
assert kwargs.get("credentials") is mock_credentials
616619
client_info = kwargs.get("client_info")
617620
assert client_info is not None
618-
assert client_info.user_agent == "ipython-" + IPython.__version__
621+
assert (
622+
client_info.user_agent
623+
== f"ipython-{IPython.__version__} bigquery-magics/{bigquery_magics.__version__}"
624+
)
619625

620626
query_job_mock.to_dataframe.assert_called_once_with(
621627
bqstorage_client=bqstorage_instance_mock,

0 commit comments

Comments
 (0)