Skip to content

Commit f9e3c6e

Browse files
mateo-berricopybara-github
authored andcommitted
Copybara import of the project:
-- 88f6792 by mateo-berri <277851410+mateo-berri@users.noreply.github.com>: fix: honor explicitly passed api_endpoint when location is "global" get_client_options defaulted the endpoint to aiplatform.googleapis.com whenever the configured location was "global", even when the caller had explicitly passed an api_endpoint, because the global-location check sat outside the api_endpoint is None guard. Gate the whole default on the endpoint being unset so an explicit override is honored for global, matching the behavior of regional locations. Fixes #6958 COPYBARA_INTEGRATE_REVIEW=#6959 from mateo-berri:fix-global-location-api-endpoint-override 7d8eac3 PiperOrigin-RevId: 944122444
1 parent c3c1836 commit f9e3c6e

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

google/cloud/aiplatform/initializer.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,10 @@ def get_client_options(
466466

467467
api_endpoint = self.api_endpoint
468468

469-
if (
470-
api_endpoint is None
471-
and not self._project
472-
and not self._location
473-
and not location_override
474-
) or (self._location == "global"):
469+
if api_endpoint is None and (
470+
(not self._project and not self._location and not location_override)
471+
or self._location == "global"
472+
):
475473
# Default endpoint is location invariant if using API key or global
476474
# location.
477475
api_endpoint = "aiplatform.googleapis.com"

tests/unit/aiplatform/test_initializer.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,19 @@ def test_create_client_with_global_location(self):
310310
assert isinstance(client, utils.PredictionClientWithOverride)
311311
assert client._transport._host == f"https://{constants.API_BASE_PATH}"
312312

313+
def test_create_client_with_global_location_and_api_endpoint(self):
314+
initializer.global_config.init(
315+
project=_TEST_PROJECT,
316+
location="global",
317+
api_endpoint="test.aiplatform.googleapis.com",
318+
)
319+
client = initializer.global_config.create_client(
320+
client_class=utils.PredictionClientWithOverride
321+
)
322+
assert initializer.global_config.location == "global"
323+
assert isinstance(client, utils.PredictionClientWithOverride)
324+
assert client._transport._host == "https://test.aiplatform.googleapis.com"
325+
313326
def test_create_client_with_global_location_and_grpc_transport(self):
314327
initializer.global_config.init(
315328
project=_TEST_PROJECT, location="global", api_transport="grpc"
@@ -437,6 +450,12 @@ def test_not_set_api_endpoint(self):
437450
"test.aiplatform.googleapis.com",
438451
"test.aiplatform.googleapis.com",
439452
),
453+
(
454+
"global",
455+
None,
456+
"test.aiplatform.googleapis.com",
457+
"test.aiplatform.googleapis.com",
458+
),
440459
],
441460
)
442461
def test_get_client_options(

0 commit comments

Comments
 (0)