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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Set prediction client when listing Endpoints #512

Merged
merged 5 commits into from Jun 30, 2021
Merged
Changes from 1 commit
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
39 changes: 39 additions & 0 deletions google/cloud/aiplatform/models.py
Expand Up @@ -324,6 +324,45 @@ def _create(
credentials=credentials,
)

def _construct_sdk_resource_from_gapic(
self,
vinnysenthil marked this conversation as resolved.
Show resolved Hide resolved
gapic_resource: proto.Message,
project: Optional[str] = None,
location: Optional[str] = None,
credentials: Optional[auth_credentials.Credentials] = None,
) -> "Endpoint":
"""Given a GAPIC Endpoint object, return the SDK representation.

Args:
gapic_resource (proto.Message):
A GAPIC representation of a Endpoint resource, usually
retrieved by a get_* or in a list_* API call.
project (str):
Optional. Project to construct Endpoint object from. If not set,
project set in aiplatform.init will be used.
location (str):
Optional. Location to construct Endpoint object from. If not set,
location set in aiplatform.init will be used.
credentials (auth_credentials.Credentials):
Optional. Custom credentials to use to construct Endpoint.
Overrides credentials set in aiplatform.init.

Returns:
Endpoint:
An initialized Endpoint resource.
"""
endpoint = self._empty_constructor(
project=project, location=location, credentials=credentials
)

endpoint._gca_resource = gapic_resource
endpoint._prediction_client = self._instantiate_prediction_client(
location=location or initializer.global_config.location,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized there is a bug here and in the implementation it's based on:

https://github.com/googleapis/python-aiplatform/blob/master/google/cloud/aiplatform/models.py#L119-L122

If passed a full resource name that doesn't match location or init.location then will instantiate the client in the incorrect location.

Please change this here and in the reference above to the use the constructed endpoint resource's location.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added calls to _get_and_validate_project_location() in both Endpoint.__init__() and Endpoint._construct_sdk_resource_from_gapic() to allow the full resource name to override location.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I realized that downstream calls in VertexAiResourceNounWithFutureManager._empty_constructor() and VertexAiResourceNounWithFutureManager.__init__() already call _get_and_validate_project_location().

I've updated the call to _instantiate_prediction_client() to use the location set by those methods instead of the location argument.

credentials=credentials,
)

return endpoint

@staticmethod
def _allocate_traffic(
traffic_split: Dict[str, int], traffic_percentage: int,
Expand Down