Skip to content

Commit 198a1b5

Browse files
authored
fix: missing reference to logged_web_access_uris (#1056)
Fixes [b/222559794](b/222559794) 🦕
1 parent d8a5e0b commit 198a1b5

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

google/cloud/aiplatform/jobs.py

+33
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,39 @@ def __init__(
850850

851851
self._logged_web_access_uris = set()
852852

853+
@classmethod
854+
def _empty_constructor(
855+
cls,
856+
project: Optional[str] = None,
857+
location: Optional[str] = None,
858+
credentials: Optional[auth_credentials.Credentials] = None,
859+
resource_name: Optional[str] = None,
860+
) -> "_RunnableJob":
861+
"""Initializes with all attributes set to None.
862+
863+
The attributes should be populated after a future is complete. This allows
864+
scheduling of additional API calls before the resource is created.
865+
866+
Args:
867+
project (str): Optional. Project of the resource noun.
868+
location (str): Optional. The location of the resource noun.
869+
credentials(google.auth.credentials.Credentials):
870+
Optional. custom credentials to use when accessing interacting with
871+
resource noun.
872+
resource_name(str): Optional. A fully-qualified resource name or ID.
873+
Returns:
874+
An instance of this class with attributes set to None.
875+
"""
876+
self = super()._empty_constructor(
877+
project=project,
878+
location=location,
879+
credentials=credentials,
880+
resource_name=resource_name,
881+
)
882+
883+
self._logged_web_access_uris = set()
884+
return self
885+
853886
@property
854887
def web_access_uris(self) -> Dict[str, Union[str, Dict[str, str]]]:
855888
"""Fetch the runnable job again and return the latest web access uris.

tests/unit/aiplatform/test_custom_job.py

+7
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,13 @@ def test_get_web_access_uris(self, get_custom_job_mock_with_enable_web_access):
547547
assert job.web_access_uris == _TEST_WEB_ACCESS_URIS
548548
break
549549

550+
def test_log_access_web_uris_after_get(
551+
self, get_custom_job_mock_with_enable_web_access
552+
):
553+
job = aiplatform.CustomJob.get(_TEST_CUSTOM_JOB_NAME)
554+
job._block_until_complete()
555+
assert job._logged_web_access_uris == set(_TEST_WEB_ACCESS_URIS.values())
556+
550557
def test_get_web_access_uris_job_succeeded(
551558
self, get_custom_job_mock_with_enable_web_access_succeeded
552559
):

tests/unit/aiplatform/test_hyperparameter_tuning_job.py

+12
Original file line numberDiff line numberDiff line change
@@ -732,3 +732,15 @@ def test_create_hyperparameter_tuning_job_with_enable_web_access(
732732
assert job.trials == []
733733

734734
caplog.clear()
735+
736+
def test_log_enable_web_access_after_get_hyperparameter_tuning_job(
737+
self, get_hyperparameter_tuning_job_mock_with_enable_web_access,
738+
):
739+
740+
hp_job = aiplatform.HyperparameterTuningJob.get(
741+
_TEST_HYPERPARAMETERTUNING_JOB_NAME
742+
)
743+
hp_job._block_until_complete()
744+
assert hp_job._logged_web_access_uris == set(
745+
test_custom_job._TEST_WEB_ACCESS_URIS.values()
746+
)

0 commit comments

Comments
 (0)