From f40f32289e1fbeb93b35e4b66f65d15528a6481c Mon Sep 17 00:00:00 2001 From: sasha-gitg <44654632+sasha-gitg@users.noreply.github.com> Date: Fri, 21 May 2021 16:51:03 -0400 Subject: [PATCH] fix: use resource name location when passed full resource name (#421) --- google/cloud/aiplatform/base.py | 3 --- tests/unit/aiplatform/test_datasets.py | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/google/cloud/aiplatform/base.py b/google/cloud/aiplatform/base.py index f183c1aedc..07e4c2fe4a 100644 --- a/google/cloud/aiplatform/base.py +++ b/google/cloud/aiplatform/base.py @@ -501,9 +501,6 @@ def _get_and_validate_project_location( RuntimeError if location is different from resource location """ - if not project and not location: - return project, location - fields = utils.extract_fields_from_resource_name( resource_name, self._resource_noun ) diff --git a/tests/unit/aiplatform/test_datasets.py b/tests/unit/aiplatform/test_datasets.py index 6b67d67a20..4c2a75c393 100644 --- a/tests/unit/aiplatform/test_datasets.py +++ b/tests/unit/aiplatform/test_datasets.py @@ -31,6 +31,7 @@ from google.cloud import bigquery from google.cloud import storage +from google.cloud.aiplatform import compat from google.cloud.aiplatform import datasets from google.cloud.aiplatform import initializer from google.cloud.aiplatform import schema @@ -401,6 +402,20 @@ def test_init_dataset_with_alt_project_and_location(self, get_dataset_mock): ) get_dataset_mock.assert_called_once_with(name=_TEST_NAME) + def test_init_dataset_with_alt_location(self, get_dataset_tabular_gcs_mock): + aiplatform.init(project=_TEST_PROJECT, location=_TEST_ALT_LOCATION) + + ds = datasets.TabularDataset(dataset_name=_TEST_NAME) + + assert ( + ds.api_client._clients[compat.DEFAULT_VERSION]._client_options.api_endpoint + == f"{_TEST_LOCATION}-{aiplatform.constants.API_BASE_PATH}" + ) + + assert _TEST_ALT_LOCATION != _TEST_LOCATION + + get_dataset_tabular_gcs_mock.assert_called_once_with(name=_TEST_NAME) + def test_init_dataset_with_project_and_alt_location(self): aiplatform.init(project=_TEST_PROJECT) with pytest.raises(RuntimeError):