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: use resource name location when passed full resource name #421

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
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