Content-Length: 445456 | pFad | http://www.github.com/googleapis/python-aiplatform/commit/95639ee1c2c9cb66624265383d4d27bed3ff7dbd

844 fix: Set prediction client when listing Endpoints (#512) · googleapis/python-aiplatform@95639ee · GitHub
Skip to content

Commit 95639ee

Browse files
authored
fix: Set prediction client when listing Endpoints (#512)
* fix: Set prediction client when listing Endpoints * Address reviewer comments * Remove redundant init() in TestEndpoints * Update location passed to _instantiate_prediction_client()
1 parent b95e040 commit 95639ee

File tree

3 files changed

+111
-49
lines changed

3 files changed

+111
-49
lines changed

google/cloud/aiplatform/base.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,9 @@ def _sync_object_with_future_result(
819819
if value:
820820
setattr(self, attribute, value)
821821

822+
@classmethod
822823
def _construct_sdk_resource_from_gapic(
823-
self,
824+
cls,
824825
gapic_resource: proto.Message,
825826
project: Optional[str] = None,
826827
location: Optional[str] = None,
@@ -846,7 +847,7 @@ def _construct_sdk_resource_from_gapic(
846847
VertexAiResourceNoun:
847848
An initialized SDK object that represents GAPIC type.
848849
"""
849-
sdk_resource = self._empty_constructor(
850+
sdk_resource = cls._empty_constructor(
850851
project=project, location=location, credentials=credentials
851852
)
852853
sdk_resource._gca_resource = gapic_resource
@@ -894,14 +895,14 @@ def _list(
894895
Returns:
895896
List[VertexAiResourceNoun] - A list of SDK resource objects
896897
"""
897-
self = cls._empty_constructor(
898+
resource = cls._empty_constructor(
898899
project=project, location=location, credentials=credentials
899900
)
900901

901902
# Fetch credentials once and re-use for all `_empty_constructor()` calls
902903
creds = initializer.global_config.credentials
903904

904-
resource_list_method = getattr(self.api_client, self._list_method)
905+
resource_list_method = getattr(resource.api_client, resource._list_method)
905906

906907
list_request = {
907908
"parent": initializer.global_config.common_location_path(
@@ -916,7 +917,7 @@ def _list(
916917
resource_list = resource_list_method(request=list_request) or []
917918

918919
return [
919-
self._construct_sdk_resource_from_gapic(
920+
cls._construct_sdk_resource_from_gapic(
920921
gapic_resource, project=project, location=location, credentials=creds
921922
)
922923
for gapic_resource in resource_list

google/cloud/aiplatform/models.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ def __init__(
116116
resource_name=endpoint_name,
117117
)
118118
self._gca_resource = self._get_gca_resource(resource_name=endpoint_name)
119+
119120
self._prediction_client = self._instantiate_prediction_client(
120-
location=location or initializer.global_config.location,
121-
credentials=credentials,
121+
location=self.location, credentials=credentials,
122122
)
123123

124124
@property
@@ -324,6 +324,46 @@ def _create(
324324
credentials=credentials,
325325
)
326326

327+
@classmethod
328+
def _construct_sdk_resource_from_gapic(
329+
cls,
330+
gapic_resource: proto.Message,
331+
project: Optional[str] = None,
332+
location: Optional[str] = None,
333+
credentials: Optional[auth_credentials.Credentials] = None,
334+
) -> "Endpoint":
335+
"""Given a GAPIC Endpoint object, return the SDK representation.
336+
337+
Args:
338+
gapic_resource (proto.Message):
339+
A GAPIC representation of a Endpoint resource, usually
340+
retrieved by a get_* or in a list_* API call.
341+
project (str):
342+
Optional. Project to construct Endpoint object from. If not set,
343+
project set in aiplatform.init will be used.
344+
location (str):
345+
Optional. Location to construct Endpoint object from. If not set,
346+
location set in aiplatform.init will be used.
347+
credentials (auth_credentials.Credentials):
348+
Optional. Custom credentials to use to construct Endpoint.
349+
Overrides credentials set in aiplatform.init.
350+
351+
Returns:
352+
Endpoint:
353+
An initialized Endpoint resource.
354+
"""
355+
endpoint = cls._empty_constructor(
356+
project=project, location=location, credentials=credentials
357+
)
358+
359+
endpoint._gca_resource = gapic_resource
360+
361+
endpoint._prediction_client = cls._instantiate_prediction_client(
362+
location=endpoint.location, credentials=credentials,
363+
)
364+
365+
return endpoint
366+
327367
@staticmethod
328368
def _allocate_traffic(
329369
traffic_split: Dict[str, int], traffic_percentage: int,

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://www.github.com/googleapis/python-aiplatform/commit/95639ee1c2c9cb66624265383d4d27bed3ff7dbd

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy