Skip to content

Commit 4c9ea5e

Browse files
authored
GitHub issue Azure#37464 (Azure#39534)
* Azure#37464 * adding unit test cases
1 parent 2008f02 commit 4c9ea5e

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

sdk/ml/azure-ai-ml/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Release History
22
## 1.26.0 (unreleased)
33

4+
### Bugs Fixed
5+
- #37464 - Allowing to update a component in register with anonymousEnvironment environment.
6+
47
## 1.25.0 (2025-02-11)
58

69
### Features Added

sdk/ml/azure-ai-ml/azure/ai/ml/operations/_environment_operations.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,15 @@ def create_or_update(self, environment: Environment) -> Environment: # type: ig
173173
),
174174
)
175175

176-
environment = _check_and_upload_env_build_context(
177-
environment=environment,
178-
operations=self,
179-
sas_uri=sas_uri,
180-
show_progress=self._show_progress,
181-
)
176+
# upload only in case of when its not registry
177+
# or successfully acquire sas_uri
178+
if not self._registry_name or sas_uri:
179+
environment = _check_and_upload_env_build_context(
180+
environment=environment,
181+
operations=self,
182+
sas_uri=sas_uri,
183+
show_progress=self._show_progress,
184+
)
182185
env_version_resource = environment._to_rest_object()
183186
env_rest_obj = (
184187
self._version_operations.begin_create_or_update(

sdk/ml/azure-ai-ml/tests/environment/unittests/test_environment_operations.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@ def test_get_no_version(self, mock_environment_operation: EnvironmentOperations)
9393

9494
def test_create_or_update(self, mock_environment_operation: EnvironmentOperations) -> None:
9595
env = load_environment(source="./tests/test_configs/environment/environment_conda.yml")
96-
with patch("azure.ai.ml.operations._environment_operations.Environment._from_rest_object", return_value=None):
96+
with patch(
97+
"azure.ai.ml.operations._environment_operations.Environment._from_rest_object", return_value=None
98+
), patch("azure.ai.ml.operations._environment_operations._check_and_upload_env_build_context") as check_upload:
9799
_ = mock_environment_operation.create_or_update(env)
100+
check_upload.assert_called_once()
98101
mock_environment_operation._version_operations.create_or_update.assert_called_once()
99102

100103
def test_create_autoincrement(

sdk/ml/azure-ai-ml/tests/environment/unittests/test_environment_operations_registry.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22

33
import pytest
44

5-
from azure.ai.ml._restclient.v2022_05_01.models import (
6-
EnvironmentVersionData,
7-
EnvironmentVersionDetails,
8-
)
9-
5+
from azure.ai.ml import load_environment
6+
from azure.ai.ml._restclient.v2022_05_01.models import EnvironmentVersionData, EnvironmentVersionDetails
107
from azure.ai.ml._scope_dependent_operations import OperationConfig, OperationScope
118
from azure.ai.ml.operations import EnvironmentOperations
12-
from azure.ai.ml import load_environment
139

1410

1511
@pytest.fixture
@@ -58,3 +54,27 @@ def test_restore_version(self, mock_environment_operation: EnvironmentOperations
5854
body=env_version,
5955
resource_group_name=mock_environment_operation._resource_group_name,
6056
)
57+
58+
def test_create_or_update_sas_uri_success(self, mock_environment_operation: EnvironmentOperations):
59+
env = load_environment(source="./tests/test_configs/environment/environment_conda.yml")
60+
with patch(
61+
"azure.ai.ml.operations._environment_operations.Environment._from_rest_object", return_value=None
62+
), patch(
63+
"azure.ai.ml.operations._environment_operations.get_sas_uri_for_registry_asset", return_value="some_sas_uri"
64+
), patch(
65+
"azure.ai.ml.operations._environment_operations._check_and_upload_env_build_context"
66+
) as check_upload:
67+
mock_environment_operation.create_or_update(env)
68+
check_upload.assert_called_once()
69+
70+
def test_create_or_update_sas_uri_failure(self, mock_environment_operation: EnvironmentOperations):
71+
env = load_environment(source="./tests/test_configs/environment/environment_conda.yml")
72+
with patch(
73+
"azure.ai.ml.operations._environment_operations.Environment._from_rest_object", return_value=None
74+
), patch(
75+
"azure.ai.ml.operations._environment_operations.get_sas_uri_for_registry_asset", return_value=None
76+
), patch(
77+
"azure.ai.ml.operations._environment_operations._check_and_upload_env_build_context"
78+
) as check_upload:
79+
mock_environment_operation.create_or_update(env)
80+
check_upload.assert_not_called()

0 commit comments

Comments
 (0)