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 #1844

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix: supplementary fix to env-based universe resolution
There's a corner case where conversion from dict to a ClientOptions
will return a universe_domain value as None that wasn't covered by
initial testing.  This updates the resolution code and adds tests to
exercise the new path.
  • Loading branch information
shollyman committed Mar 6, 2024
commit 8b7e2f65146bddea05094de584d9f4432b2e00a6
5 changes: 2 additions & 3 deletions google/cloud/bigquery/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ def _get_client_universe(
if isinstance(client_options, dict):
client_options = client_options_lib.from_dict(client_options)
universe = _DEFAULT_UNIVERSE
if hasattr(client_options, "universe_domain"):
options_universe = getattr(client_options, "universe_domain")
if options_universe is not None and len(options_universe) > 0:
options_universe = getattr(client_options, "universe_domain", None)
if options_universe and isinstance(options_universe, str) and len(options_universe) > 0:
universe = options_universe
else:
env_universe = os.getenv(_UNIVERSE_DOMAIN_ENV)
Expand Down
14 changes: 13 additions & 1 deletion tests/unit/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,22 @@ def test_with_environ(self):

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

@mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"})
def test_with_environ_and_dict(self):
from google.cloud.bigquery._helpers import _get_client_universe
options = {"credentials_file": "file.json"},
self.assertEqual("foo.com", _get_client_universe(options))

@mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"})
def test_with_environ_and_empty_options(self):
from google.cloud.bigquery._helpers import _get_client_universe
from google.api_core import client_options
options = client_options.from_dict({})
self.assertEqual("foo.com", _get_client_universe(options))

@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))


Expand Down