Skip to content

Commit

Permalink
fix: missing reference to logged_web_access_uris (#1056)
Browse files Browse the repository at this point in the history
Fixes [b/222559794](b/222559794) 🦕
  • Loading branch information
sasha-gitg authored Mar 4, 2022
1 parent d8a5e0b commit 198a1b5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
33 changes: 33 additions & 0 deletions google/cloud/aiplatform/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,39 @@ def __init__(

self._logged_web_access_uris = set()

@classmethod
def _empty_constructor(
cls,
project: Optional[str] = None,
location: Optional[str] = None,
credentials: Optional[auth_credentials.Credentials] = None,
resource_name: Optional[str] = None,
) -> "_RunnableJob":
"""Initializes with all attributes set to None.
The attributes should be populated after a future is complete. This allows
scheduling of additional API calls before the resource is created.
Args:
project (str): Optional. Project of the resource noun.
location (str): Optional. The location of the resource noun.
credentials(google.auth.credentials.Credentials):
Optional. custom credentials to use when accessing interacting with
resource noun.
resource_name(str): Optional. A fully-qualified resource name or ID.
Returns:
An instance of this class with attributes set to None.
"""
self = super()._empty_constructor(
project=project,
location=location,
credentials=credentials,
resource_name=resource_name,
)

self._logged_web_access_uris = set()
return self

@property
def web_access_uris(self) -> Dict[str, Union[str, Dict[str, str]]]:
"""Fetch the runnable job again and return the latest web access uris.
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/aiplatform/test_custom_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,13 @@ def test_get_web_access_uris(self, get_custom_job_mock_with_enable_web_access):
assert job.web_access_uris == _TEST_WEB_ACCESS_URIS
break

def test_log_access_web_uris_after_get(
self, get_custom_job_mock_with_enable_web_access
):
job = aiplatform.CustomJob.get(_TEST_CUSTOM_JOB_NAME)
job._block_until_complete()
assert job._logged_web_access_uris == set(_TEST_WEB_ACCESS_URIS.values())

def test_get_web_access_uris_job_succeeded(
self, get_custom_job_mock_with_enable_web_access_succeeded
):
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/aiplatform/test_hyperparameter_tuning_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,3 +732,15 @@ def test_create_hyperparameter_tuning_job_with_enable_web_access(
assert job.trials == []

caplog.clear()

def test_log_enable_web_access_after_get_hyperparameter_tuning_job(
self, get_hyperparameter_tuning_job_mock_with_enable_web_access,
):

hp_job = aiplatform.HyperparameterTuningJob.get(
_TEST_HYPERPARAMETERTUNING_JOB_NAME
)
hp_job._block_until_complete()
assert hp_job._logged_web_access_uris == set(
test_custom_job._TEST_WEB_ACCESS_URIS.values()
)

0 comments on commit 198a1b5

Please sign in to comment.