diff --git a/src/machinelearningservices/azext_mlv2/manual/custom/deployment_template.py b/src/machinelearningservices/azext_mlv2/manual/custom/deployment_template.py index df8befc614a..103af1030b7 100644 --- a/src/machinelearningservices/azext_mlv2/manual/custom/deployment_template.py +++ b/src/machinelearningservices/azext_mlv2/manual/custom/deployment_template.py @@ -144,13 +144,25 @@ def _ml_deployment_template_update( ) try: - deployment_template = ml_client.deployment_templates.get(name=parameters["name"], version=parameters["version"]) - - # Only update optional fields if they are explicitly present in parameters + deployment_template = ml_client.deployment_templates.get( + name=parameters["name"], version=parameters["version"] + ) + + # Detect if user tried to update immutable fields + original = deployment_template._to_dict() # pylint: disable=protected-access + mutable_fields = {"tags", "description"} + for key, value in parameters.items(): + if key not in mutable_fields and key in original and original[key] != value: + raise ValueError( + f"Field '{key}' is immutable and cannot be updated. " + "Only 'tags' and 'description' can be modified." + ) + + # Apply mutable field changes if "description" in parameters: - deployment_template.description = parameters.get("description") + deployment_template.description = parameters["description"] if "tags" in parameters: - deployment_template.tags = parameters.get("tags") + deployment_template.tags = parameters["tags"] deployment_template_result = ml_client.deployment_templates.create_or_update(deployment_template) diff --git a/src/machinelearningservices/azext_mlv2/tests/latest/recordings/test_04_deployment_template_update.yaml b/src/machinelearningservices/azext_mlv2/tests/latest/recordings/test_04_deployment_template_update.yaml index 4d20566deda..9ef4089b949 100644 --- a/src/machinelearningservices/azext_mlv2/tests/latest/recordings/test_04_deployment_template_update.yaml +++ b/src/machinelearningservices/azext_mlv2/tests/latest/recordings/test_04_deployment_template_update.yaml @@ -325,7 +325,7 @@ interactions: response: body: string: '{"type": "deploymenttemplates", "name": "test-deployment-template", - "stage": "Archived", "version": "1", "description": "Updated_description_for_deployment_template_testing", + "stage": "Development", "version": "1", "description": "Updated_description_for_deployment_template_testing", "createdBy": {"userObjectId": "e7ae4769-61f9-4372-8392-79c1757a70b0", "userTenantId": "72f988bf-86f1-41af-91ab-2d7cd011db47", "userName": "Kshitij Chawla"}, "capabilities": [], "createdTime": "2025-11-07T07:25:14.9461737+00:00", "modifiedTime": "2025-11-07T16:40:14.7312037+00:00", @@ -443,7 +443,7 @@ interactions: code: 200 message: OK - request: - body: '{"stage": "Archived", "description": "Updated_description_for_deployment_template_testing", + body: '{"stage": "Development", "description": "Updated_description_for_deployment_template_testing", "tags": {"stage": "Open", "environment": "test", "updated": "True"}, "deploymentTemplateType": "Managed", "environmentId": "azureml://registries/kchawla-reg/environments/kchawla-environment/versions/1", "environmentVariables": {"MODEL_BASE_PATH": "/var/azureml-app/azureml-models/tfs-model1/1", diff --git a/src/machinelearningservices/azext_mlv2/tests/latest/recordings/test_10_deployment_template_update_multiple_tags.yaml b/src/machinelearningservices/azext_mlv2/tests/latest/recordings/test_10_deployment_template_update_multiple_tags.yaml index 671a6c8eaed..9a17c5a70bd 100644 --- a/src/machinelearningservices/azext_mlv2/tests/latest/recordings/test_10_deployment_template_update_multiple_tags.yaml +++ b/src/machinelearningservices/azext_mlv2/tests/latest/recordings/test_10_deployment_template_update_multiple_tags.yaml @@ -325,7 +325,7 @@ interactions: response: body: string: '{"type": "deploymenttemplates", "name": "test-deployment-template", - "stage": "Archived", "version": "1", "description": "Updated_description_for_deployment_template_testing", + "stage": "Development", "version": "1", "description": "Updated_description_for_deployment_template_testing", "createdBy": {"userObjectId": "e7ae4769-61f9-4372-8392-79c1757a70b0", "userTenantId": "72f988bf-86f1-41af-91ab-2d7cd011db47", "userName": "Kshitij Chawla"}, "capabilities": [], "createdTime": "2025-11-07T07:25:14.9461737+00:00", "modifiedTime": "2025-11-07T16:40:14.7312037+00:00", @@ -443,7 +443,7 @@ interactions: code: 200 message: OK - request: - body: '{"stage": "Archived", "description": "Updated_description_for_deployment_template_testing", + body: '{"stage": "Development", "description": "Updated_description_for_deployment_template_testing", "tags": {"stage": "Open", "environment": "test", "updated": "True", "author": "test-automation", "project": "cli-testing", "iteration": "second-update", "validated": "True"}, "deploymentTemplateType": "Managed", "environmentId": "azureml://registries/kchawla-reg/environments/kchawla-environment/versions/1",