Skip to content

Commit 214f2ce

Browse files
authored
[ML] Adding validations not to allow both workspace_name and registry_name together in ml_client (#26562)
1 parent 2a445fe commit 214f2ce

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

sdk/ml/azure-ai-ml/azure/ai/ml/_ml_client.py

+8
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ def __init__(
155155

156156
if credential is None:
157157
raise ValueError("credential can not be None")
158+
159+
if registry_name and workspace_name:
160+
raise ValidationException(
161+
message="Both workspace_name and registry_name cannot be used together, for the ml_client.",
162+
no_personal_data_message="Both workspace_name and registry_name are used for ml_client.",
163+
target=ErrorTarget.GENERAL,
164+
error_category=ErrorCategory.USER_ERROR,
165+
)
158166
if not registry_name:
159167
_validate_missing_sub_or_rg_and_raise(subscription_id, resource_group_name)
160168
self._credential = credential

sdk/ml/azure-ai-ml/tests/conftest.py

-3
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ def registry_client(e2e_ws_scope: OperationScope, auth: ClientSecretCredential)
243243
credential=auth,
244244
subscription_id=e2e_ws_scope.subscription_id,
245245
resource_group_name=e2e_ws_scope.resource_group_name,
246-
workspace_name=e2e_ws_scope.workspace_name,
247246
logging_enable=getenv(E2E_TEST_LOGGING_ENABLED),
248247
registry_name="testFeed",
249248
)
@@ -254,8 +253,6 @@ def only_registry_client(e2e_ws_scope: OperationScope, auth: ClientSecretCredent
254253
"""return a machine learning client using default e2e testing workspace"""
255254
return MLClient(
256255
credential=auth,
257-
subscription_id=e2e_ws_scope.subscription_id,
258-
resource_group_name=e2e_ws_scope.resource_group_name,
259256
logging_enable=getenv(E2E_TEST_LOGGING_ENABLED),
260257
registry_name="testFeed",
261258
)

sdk/ml/azure-ai-ml/tests/internal_utils/unittests/test_ml_client.py

+13
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,16 @@ def test_ml_client_with_no_rg_sub_for_ws_throws(
448448
message
449449
== "Both subscription id and resource group are required for this operation, missing subscription id and resource group"
450450
)
451+
452+
def test_ml_client_with_both_workspace_registry_names_throws(self, e2e_ws_scope: OperationScope, auth: ClientSecretCredential) -> None:
453+
with pytest.raises(ValidationException) as exception:
454+
MLClient(
455+
credential=auth,
456+
workspace_name=e2e_ws_scope.workspace_name,
457+
registry_name="testfeed",
458+
)
459+
message = exception.value.args[0]
460+
assert (
461+
message
462+
== "Both workspace_name and registry_name cannot be used together, for the ml_client."
463+
)

0 commit comments

Comments
 (0)