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: missing reference to logged_web_access_uris #1056

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
)