Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: supplementary fix to env-based universe resolution #1847

Merged
merged 6 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 12 additions & 13 deletions google/cloud/bigquery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,19 @@ def __init__(
bq_host = _get_bigquery_host()
kw_args["api_endpoint"] = bq_host if bq_host != _DEFAULT_HOST else None
client_universe = None
if client_options:
if isinstance(client_options, dict):
client_options = google.api_core.client_options.from_dict(
client_options
if client_options is None:
Linchin marked this conversation as resolved.
Show resolved Hide resolved
client_options = {}
if isinstance(client_options, dict):
client_options = google.api_core.client_options.from_dict(client_options)
if client_options.api_endpoint:
Linchin marked this conversation as resolved.
Show resolved Hide resolved
api_endpoint = client_options.api_endpoint
kw_args["api_endpoint"] = api_endpoint
else:
client_universe = _get_client_universe(client_options)
if client_universe != _DEFAULT_UNIVERSE:
kw_args["api_endpoint"] = _DEFAULT_HOST_TEMPLATE.replace(
"{UNIVERSE_DOMAIN}", client_universe
)
if client_options.api_endpoint:
api_endpoint = client_options.api_endpoint
kw_args["api_endpoint"] = api_endpoint
else:
client_universe = _get_client_universe(client_options)
if client_universe != _DEFAULT_UNIVERSE:
kw_args["api_endpoint"] = _DEFAULT_HOST_TEMPLATE.replace(
"{UNIVERSE_DOMAIN}", client_universe
)
# Ensure credentials and universe are not in conflict.
if hasattr(self, "_credentials") and client_universe is not None:
_validate_universe(client_universe, self._credentials)
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import itertools
import json
import operator
import os
import unittest
from unittest import mock
import warnings
Expand Down Expand Up @@ -171,6 +172,17 @@ def test_ctor_w_empty_client_options(self):
client._connection.API_BASE_URL, client._connection.DEFAULT_API_ENDPOINT
)

@mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"})
def test_ctor_w_only_env_universe(self):
creds = _make_credentials()
http = object()
client = self._make_one(
project=self.PROJECT,
credentials=creds,
_http=http,
)
self.assertEqual(client._connection.API_BASE_URL, "https://bigquery.foo.com")

def test_ctor_w_client_options_dict(self):
creds = _make_credentials()
http = object()
Expand Down