Skip to content

Commit 50a34a0

Browse files
authored
[ML][Pipelines] Bugfix: component version auto increment under non-registry create operation (Azure#28367)
* partly revert component create operation to fix component version auto increment bug for non-registry scenario * re-enable skip test and update recording * revert test code changes for breaking unit tests * update recordings for breaking end-to-end tests * not apply auto increment version for anonymous component * update recordings for breaking tests * update recordings for breaking tests
1 parent 356f287 commit 50a34a0

File tree

26 files changed

+5293
-7435
lines changed

26 files changed

+5293
-7435
lines changed

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

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
# )
3030
from azure.ai.ml._utils._asset_utils import (
3131
_archive_or_restore,
32+
_create_or_update_autoincrement,
3233
_get_latest,
3334
_get_next_version_from_container,
3435
_resolve_label_to_asset,
@@ -295,7 +296,11 @@ def create_or_update(
295296
component = _refine_component(component)
296297
if version is not None:
297298
component.version = version
298-
if not component.version and component._auto_increment_version:
299+
# In non-registry scenario, if component does not have version, no need to get next version here.
300+
# As Component property version has setter that updates `_auto_increment_version` in-place, then
301+
# a component will get a version after its creation, and it will always use this version in its
302+
# future creation operations, which breaks version auto increment mechanism.
303+
if self._registry_name and not component.version and component._auto_increment_version:
299304
component.version = _get_next_version_from_container(
300305
name=component.name,
301306
container_operation=self._container_operation,
@@ -340,14 +345,27 @@ def create_or_update(
340345
polling_wait(poller=poller, start_time=start_time, message=message, timeout=None)
341346

342347
else:
343-
result = self._version_operation.create_or_update(
344-
name=name,
345-
version=version,
346-
resource_group_name=self._resource_group_name,
347-
workspace_name=self._workspace_name,
348-
body=rest_component_resource,
349-
**self._init_args,
350-
)
348+
# _auto_increment_version can be True for non-registry component creation operation;
349+
# and anonymous component should use hash as version
350+
if not component._is_anonymous and component._auto_increment_version:
351+
result = _create_or_update_autoincrement(
352+
name=name,
353+
body=rest_component_resource,
354+
version_operation=self._version_operation,
355+
container_operation=self._container_operation,
356+
resource_group_name=self._operation_scope.resource_group_name,
357+
workspace_name=self._workspace_name,
358+
**self._init_args,
359+
)
360+
else:
361+
result = self._version_operation.create_or_update(
362+
name=name,
363+
version=version,
364+
resource_group_name=self._resource_group_name,
365+
workspace_name=self._workspace_name,
366+
body=rest_component_resource,
367+
**self._init_args,
368+
)
351369
except Exception as e:
352370
raise e
353371

sdk/ml/azure-ai-ml/tests/component/e2etests/test_component.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,6 @@ def test_tensorflow_component(
511511
tensorflow_component_resource = client.components.create_or_update(component_entity)
512512
assert tensorflow_component_resource.distribution.__dict__ == tensorflow_distribution(has_strs=True)
513513

514-
@pytest.mark.skip(
515-
"Could not rerecord the test , errors: (UserError) Failed to update component test_81585734883"
516-
)
517514
def test_command_component_create_autoincrement(self, client: MLClient, randstr: Callable[[str], str]) -> None:
518515
component_name = randstr("component_name")
519516
params_override = [{"name": component_name}]

sdk/ml/azure-ai-ml/tests/component/unittests/test_component_operations.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,13 @@ def test_create_autoincrement(self, mock_component_operation: ComponentOperation
8080
assert component._auto_increment_version
8181
with patch.object(ComponentOperations, "_resolve_arm_id_or_upload_dependencies") as mock_thing, patch(
8282
"azure.ai.ml.operations._component_operations.Component._from_rest_object", return_value=component
83-
) , patch(
84-
"azure.ai.ml.operations._component_operations._get_next_version_from_container", return_value="version"
85-
) as mock_nextver:
83+
):
8684
mock_component_operation.create_or_update(component)
87-
mock_nextver.assert_called_once()
85+
mock_thing.assert_called_once()
8886

8987
mock_component_operation._version_operation.create_or_update.assert_called_once_with(
9088
name=component.name,
91-
version=mock_nextver.return_value,
89+
version=mock_component_operation._container_operation.get().properties.next_version,
9290
body=component._to_rest_object(),
9391
resource_group_name=mock_component_operation._operation_scope.resource_group_name,
9492
workspace_name=mock_component_operation._operation_scope.workspace_name,

sdk/ml/azure-ai-ml/tests/component/unittests/test_parallel_component_operations.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,20 @@ def test_create_autoincrement(
8383
)
8484
assert component._auto_increment_version
8585
with patch.object(ComponentOperations, "_resolve_arm_id_or_upload_dependencies") as mock_thing, patch(
86-
"azure.ai.ml.operations._component_operations.Component._from_rest_object", return_value=component
87-
) , patch(
88-
"azure.ai.ml.operations._component_operations._get_next_version_from_container", return_value="version"
89-
) as mock_nextver:
86+
"azure.ai.ml.operations._component_operations.Component._from_rest_object",
87+
return_value=component,
88+
):
9089
mock_component_operation.create_or_update(component)
91-
mock_nextver.assert_called_once()
90+
mock_thing.assert_called_once()
9291

92+
mock_component_operation._container_operation.get.assert_called_once_with(
93+
name=component.name,
94+
resource_group_name=mock_component_operation._operation_scope.resource_group_name,
95+
workspace_name=mock_component_operation._operation_scope.workspace_name,
96+
)
9397
mock_component_operation._version_operation.create_or_update.assert_called_once_with(
9498
name=component.name,
95-
version=mock_nextver.return_value,
99+
version=mock_component_operation._container_operation.get().properties.next_version,
96100
body=component._to_rest_object(),
97101
resource_group_name=mock_component_operation._operation_scope.resource_group_name,
98102
workspace_name=mock_component_operation._operation_scope.workspace_name,

0 commit comments

Comments
 (0)