Skip to content

Commit

Permalink
fix: use resource name location when passed full resource name (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
sasha-gitg committed May 21, 2021
1 parent 2abca93 commit f40f322
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 0 additions & 3 deletions google/cloud/aiplatform/base.py
Expand Up @@ -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
)
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/aiplatform/test_datasets.py
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit f40f322

Please sign in to comment.