diff --git a/google/cloud/aiplatform/metadata/schema/utils.py b/google/cloud/aiplatform/metadata/schema/utils.py index 555e9380b5..83b48b4d59 100644 --- a/google/cloud/aiplatform/metadata/schema/utils.py +++ b/google/cloud/aiplatform/metadata/schema/utils.py @@ -19,6 +19,11 @@ from typing import Optional, Dict, List from dataclasses import dataclass +_RESOURCE_NAME_REGEX = re.compile( + r"^projects/(?P[\w-]+)/locations/(?P[\w-]+)" + r"(?:/metadataStores/(?P[\w-]+))?/[\w-]+/(?P[\w-]+)(?P@[\w-]+)?$" +) + @dataclass class PredictSchemata: @@ -349,10 +354,7 @@ def create_uri_from_resource_name(resource_name: str) -> str: ValueError: If resource_name does not match the specified format. """ # TODO: support nested resource names such as models/123/evaluations/456 - match_results = re.match( - r"^projects\/(?P[\w-]+)\/locations\/(?P[\w-]+)(\/metadataStores\/(?P[\w-]+))?\/[\w-]+\/(?P[\w-]+)(?P@[\w-]+)?$", - resource_name, - ) + match_results = _RESOURCE_NAME_REGEX.match(resource_name) if not match_results: raise ValueError(f"Invalid resource_name format for {resource_name}.")