@@ -4701,6 +4701,42 @@ def test_init_with_version_arg(self, get_model_with_version):
47014701 # The Model yielded from upload SHOULD have a version in the versioned resource name
47024702 assert model .versioned_resource_name .endswith (f"@{ _TEST_VERSION_ID } " )
47034703
4704+ def test_sync_gca_resource_uses_versioned_name (self , get_model_with_version ):
4705+ # Regression test for https://github.com/googleapis/python-aiplatform/issues/2619
4706+ # _sync_gca_resource must use versioned_resource_name so the non-default
4707+ # version is not silently replaced by the default version.
4708+ model = models .Model (model_name = _TEST_MODEL_NAME , version = _TEST_VERSION_ID )
4709+ get_model_with_version .reset_mock ()
4710+
4711+ model ._sync_gca_resource ()
4712+
4713+ versioned_name = models .ModelRegistry ._get_versioned_name (
4714+ _TEST_MODEL_PARENT , _TEST_VERSION_ID
4715+ )
4716+ get_model_with_version .assert_called_once_with (
4717+ name = versioned_name , retry = base ._DEFAULT_RETRY
4718+ )
4719+
4720+ def test_update_preserves_version (
4721+ self , update_model_mock , get_model_with_version
4722+ ):
4723+ # Regression test for https://github.com/googleapis/python-aiplatform/issues/2619
4724+ # Model.update() calls _sync_gca_resource(); verify it fetches the versioned name.
4725+ model = models .Model (model_name = _TEST_MODEL_NAME , version = _TEST_VERSION_ID )
4726+ get_model_with_version .reset_mock ()
4727+
4728+ model .update (display_name = _TEST_MODEL_NAME )
4729+
4730+ versioned_name = models .ModelRegistry ._get_versioned_name (
4731+ _TEST_MODEL_PARENT , _TEST_VERSION_ID
4732+ )
4733+ get_model_with_version .assert_called_once_with (
4734+ name = versioned_name , retry = base ._DEFAULT_RETRY
4735+ )
4736+ # Version must still be intact after update
4737+ assert model .version_id == _TEST_VERSION_ID
4738+ assert model .versioned_resource_name .endswith (f"@{ _TEST_VERSION_ID } " )
4739+
47044740 @pytest .mark .parametrize (
47054741 "parent,location,project" ,
47064742 [
0 commit comments