diff --git a/sdk/ml/azure-ai-ml/CHANGELOG.md b/sdk/ml/azure-ai-ml/CHANGELOG.md index bd975fafa7ad..047fe1fb1083 100644 --- a/sdk/ml/azure-ai-ml/CHANGELOG.md +++ b/sdk/ml/azure-ai-ml/CHANGELOG.md @@ -8,6 +8,7 @@ - Fixed cross-tenant registry endpoint resolution for deployment template operations by using the registry discovery API instead of ARM calls. - Fixed deployment template update failing with immutable field errors by ensuring `allowedInstanceType` and `allowedEnvironmentVariableOverrides` are properly round-tripped during serialization. +- Fixed `MLClient.models.list` ignoring the `list_view_type` filter when the client is scoped to a registry. Archived/active filtering on registry models now works as documented. ### Other Changes diff --git a/sdk/ml/azure-ai-ml/azure/ai/ml/operations/_model_operations.py b/sdk/ml/azure-ai-ml/azure/ai/ml/operations/_model_operations.py index 2d6a04ce9afc..a29f6f3ac715 100644 --- a/sdk/ml/azure-ai-ml/azure/ai/ml/operations/_model_operations.py +++ b/sdk/ml/azure-ai-ml/azure/ai/ml/operations/_model_operations.py @@ -579,6 +579,7 @@ def list( name=name, registry_name=self._registry_name, cls=lambda objs: [Model._from_rest_object(obj) for obj in objs], + list_view_type=list_view_type, **self._scope_kwargs, ) if self._registry_name diff --git a/sdk/ml/azure-ai-ml/tests/model/unittests/test_model_operations.py b/sdk/ml/azure-ai-ml/tests/model/unittests/test_model_operations.py index f01427a6ea32..6215b7d02783 100644 --- a/sdk/ml/azure-ai-ml/tests/model/unittests/test_model_operations.py +++ b/sdk/ml/azure-ai-ml/tests/model/unittests/test_model_operations.py @@ -12,6 +12,7 @@ ModelVersionProperties as ModelVersionDetails, ) from azure.ai.ml._scope_dependent_operations import OperationConfig, OperationScope +from azure.ai.ml.constants import ListViewType from azure.ai.ml.entities._assets import Model from azure.ai.ml.entities._assets._artifacts.artifact import ArtifactStorageInfo from azure.ai.ml.exceptions import ErrorTarget, ValidationException @@ -183,6 +184,31 @@ def test_list(self, mock_model_operation: ModelOperations) -> None: mock_model_operation.list(name="random_string") mock_model_operation._model_versions_operation.list.assert_called_once() + @patch.object(Model, "_from_rest_object", new=Mock()) + def test_list_name_forwards_list_view_type_registry_and_workspace( + self, mock_model_operation: ModelOperations, mock_model_operation_reg: ModelOperations + ) -> None: + mock_model_operation._model_versions_operation.list.return_value = [Mock(Model)] + mock_model_operation_reg._model_versions_operation.list.return_value = [Mock(Model)] + + list(mock_model_operation.list(name="my-model", stage="Production", list_view_type=ListViewType.ARCHIVED_ONLY)) + workspace_kwargs = mock_model_operation._model_versions_operation.list.call_args.kwargs + assert workspace_kwargs["name"] == "my-model" + assert workspace_kwargs["workspace_name"] == mock_model_operation._workspace_name + assert workspace_kwargs["list_view_type"] == ListViewType.ARCHIVED_ONLY + assert workspace_kwargs["stage"] == "Production" + + list( + mock_model_operation_reg.list( + name="my-model", stage="Production", list_view_type=ListViewType.ARCHIVED_ONLY + ) + ) + registry_kwargs = mock_model_operation_reg._model_versions_operation.list.call_args.kwargs + assert registry_kwargs["name"] == "my-model" + assert registry_kwargs["registry_name"] == mock_model_operation_reg._registry_name + assert registry_kwargs["list_view_type"] == ListViewType.ARCHIVED_ONLY + assert "stage" not in registry_kwargs + def test_archive_version(self, mock_model_operation: ModelOperations) -> None: name = "random_string" model_version = Mock(ModelVersionData(properties=Mock(ModelVersionDetails())))