Skip to content

Commit 65300c4

Browse files
jaycee-licopybara-github
authored andcommitted
chore: check default MetadataStore when creating Artifacts
PiperOrigin-RevId: 498214023
1 parent 372ab8d commit 65300c4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

google/cloud/aiplatform/metadata/artifact.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,11 @@ def create(
344344
"aiplatform.metadata.artifact.Artifact.create"
345345
)
346346

347+
if metadata_store_id == "default":
348+
metadata_store._MetadataStore.ensure_default_metadata_store_exists(
349+
project=project, location=location, credentials=credentials
350+
)
351+
347352
return cls._create(
348353
resource_id=resource_id,
349354
schema_title=schema_title,

tests/unit/aiplatform/test_metadata_resources.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
Execution as GapicExecution,
3838
Context as GapicContext,
3939
Artifact as GapicArtifact,
40+
MetadataStore as GapicMetadataStore,
4041
AddContextArtifactsAndExecutionsResponse,
4142
)
4243

@@ -361,6 +362,17 @@ def update_artifact_mock():
361362
yield update_artifact_mock
362363

363364

365+
@pytest.fixture
366+
def get_metadata_store_mock():
367+
with patch.object(
368+
MetadataServiceClient, "get_metadata_store"
369+
) as get_metadata_store_mock:
370+
get_metadata_store_mock.return_value = GapicMetadataStore(
371+
name=_TEST_METADATA_STORE
372+
)
373+
yield get_metadata_store_mock
374+
375+
364376
@pytest.mark.usefixtures("google_auth_mock")
365377
class TestContext:
366378
def setup_method(self):
@@ -799,7 +811,9 @@ def test_add_vertex_model(
799811
events=[Event(artifact=_TEST_ARTIFACT_NAME, type_=Event.Type.OUTPUT)],
800812
)
801813

802-
@pytest.mark.usefixtures("get_execution_mock", "get_model_with_version_mock")
814+
@pytest.mark.usefixtures(
815+
"get_execution_mock", "get_model_with_version_mock", "get_metadata_store_mock"
816+
)
803817
def test_add_vertex_model_not_resolved(
804818
self, add_execution_events_mock, list_artifact_empty_mock, create_artifact_mock
805819
):

0 commit comments

Comments
 (0)