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: augment universe_domain handling #1837

Merged
merged 15 commits into from
Mar 5, 2024
Prev Previous commit
Next Next commit
reviewer feedback
  • Loading branch information
shollyman committed Mar 4, 2024
commit 2f5b49e094fb3fbb4339180970fddac0a319b18c
4 changes: 2 additions & 2 deletions google/cloud/bigquery/_helpers.py
Expand Up @@ -83,11 +83,11 @@ def _get_client_universe(
universe = _DEFAULT_UNIVERSE
if hasattr(client_options, "universe_domain"):
options_universe = getattr(client_options, "universe_domain")
shollyman marked this conversation as resolved.
Show resolved Hide resolved
if options_universe is not None:
if options_universe is not None and len(env_universe) > 0:
universe = options_universe
else:
env_universe = os.getenv(_UNIVERSE_DOMAIN_ENV)
if isinstance(env_universe, str):
if isinstance(env_universe, str) and len(env_universe) > 0:
universe = env_universe
return universe

Expand Down
1 change: 0 additions & 1 deletion google/cloud/bigquery/client.py
Expand Up @@ -268,7 +268,6 @@ def __init__(
_validate_universe(client_universe, self._credentials)

self._connection = Connection(self, **kw_args)

self._location = location
self._default_load_job_config = copy.deepcopy(default_load_job_config)

Expand Down
14 changes: 13 additions & 1 deletion tests/unit/test__helpers.py
Expand Up @@ -41,7 +41,13 @@ def test_with_dict(self):
options = {"universe_domain": "foo.com"}
self.assertEqual("foo.com", _get_client_universe(options))

def test_with_clientoptions(self):
def test_with_dict_empty(self):
from google.cloud.bigquery._helpers import _get_client_universe

options = {"universe_domain": ""}
self.assertEqual("googleapis.com", _get_client_universe(options))

def test_with_client_options(self):
from google.cloud.bigquery._helpers import _get_client_universe
from google.api_core import client_options

Expand All @@ -54,6 +60,12 @@ def test_with_environ(self):

self.assertEqual("foo.com", _get_client_universe(None))

@mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": ""})
def test_with_environ_empty(self):
from google.cloud.bigquery._helpers import _get_client_universe

self.assertEqual("googleapis.com", _get_client_universe(None))


class Test_validate_universe(unittest.TestCase):
def test_with_none(self):
Expand Down