Skip to content

[ml] Fix jobs partial update across all job types#47819

Open
Chakradhar886 wants to merge 6 commits into
mainfrom
hotfix/ml-jobs-update-metadata-shortcut
Open

[ml] Fix jobs partial update across all job types#47819
Chakradhar886 wants to merge 6 commits into
mainfrom
hotfix/ml-jobs-update-metadata-shortcut

Conversation

@Chakradhar886

Copy link
Copy Markdown
Member

Root bug: ml_client.jobs.get(name) -> mutate -> jobs.create_or_update(job) fails for AutoML, Command, Pipeline, Sweep and Spark. Each job type raises a different serializer or MFE PUT comparator error (QueueSettings._to_rest_object AttributeError for Sweep, InputBindings/output-binding UserError for Pipeline and Spark, registry-scope UserError for Command, 'Input path can't be empty' for AutoML).

This change adds two intentionally narrow fixes:

  1. A new public jobs.update(name, *, display_name, description, tags, properties) API that routes through the RunHistory PATCH endpoint used by ML Studio's portal for inline edits. The endpoint is job-type agnostic and merges tags/properties instead of replacing them.

  2. A temporary shortcut inside create_or_update that detects the 'fetched job with only metadata changes' case (job carries an ARM id, no compute/experiment_name kwargs supplied) and routes it through the same RunHistory PATCH path. Any failure inside the shortcut falls through to the original create/update logic so brand-new job creation is bit-for-bit unchanged.

Verified live against AutoML, Command, Pipeline, Sweep and Spark jobs; MFE GET (api-version 2024-10-01) confirms displayName and merged tags persisted server-side.

Description

Please add an informative description that covers that changes made by the pull request and link all relevant issues.

If an SDK is being regenerated based on a new API spec, a link to the pull request containing these API spec changes should be included above.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Root bug: ml_client.jobs.get(name) -> mutate -> jobs.create_or_update(job) fails for AutoML, Command, Pipeline, Sweep and Spark. Each job type raises a different serializer or MFE PUT comparator error (QueueSettings._to_rest_object AttributeError for Sweep, InputBindings/output-binding UserError for Pipeline and Spark, registry-scope UserError for Command, 'Input path can't be empty' for AutoML).

This change adds two intentionally narrow fixes:

1. A new public jobs.update(name, *, display_name, description, tags, properties) API that routes through the RunHistory PATCH endpoint used by ML Studio's portal for inline edits. The endpoint is job-type agnostic and merges tags/properties instead of replacing them.

2. A temporary shortcut inside create_or_update that detects the 'fetched job with only metadata changes' case (job carries an ARM id, no compute/experiment_name kwargs supplied) and routes it through the same RunHistory PATCH path. Any failure inside the shortcut falls through to the original create/update logic so brand-new job creation is bit-for-bit unchanged.

Verified live against AutoML, Command, Pipeline, Sweep and Spark jobs; MFE GET (api-version 2024-10-01) confirms displayName and merged tags persisted server-side.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a bug in azure-ai-ml where the common "fetch a job, mutate it, resubmit via jobs.create_or_update(job)" pattern fails for AutoML, Command, Pipeline, Sweep, and Spark jobs (each raising a different serializer or MFE PUT comparator error). The change touches a single file, sdk/ml/azure-ai-ml/azure/ai/ml/operations/_job_operations.py, and introduces two related fixes that route metadata-only edits through the RunHistory PATCH endpoint used by ML Studio's portal.

Changes:

  • Adds a new public JobOperations.update(name, *, display_name, description, tags, properties) API that patches job metadata uniformly across all job types via RunHistory add_or_modify_by_experiment_name.
  • Adds a "TEMPORARY HOTFIX" shortcut inside create_or_update that detects a fetched job (ARM id present, no compute/experiment_name keyword override) and routes it through the same RunHistory PATCH path, falling back to the original create/update flow on any exception.
  • Reuses the existing pipeline-handling pattern (_get_job_get_job_2401 refetch → PipelineChildJobError rejection) already used by archive/restore.

refreshed = self._get_job(name)
if refreshed.properties.job_type == RestJobType.PIPELINE:
refreshed = self._get_job_2401(name)
return Job._from_rest_object(refreshed)
Comment on lines +958 to +966
def update(
self,
name: str,
*,
display_name: Optional[str] = None,
description: Optional[str] = None,
tags: Optional[Dict[str, str]] = None,
properties: Optional[Dict[str, str]] = None,
) -> Job:
Comment on lines +958 to +966
def update(
self,
name: str,
*,
display_name: Optional[str] = None,
description: Optional[str] = None,
tags: Optional[Dict[str, str]] = None,
properties: Optional[Dict[str, str]] = None,
) -> Job:
Comment on lines +742 to +747
if (
getattr(job, "id", None)
and getattr(job, "name", None)
and compute is None
and experiment_name is None
):
Comment thread sdk/ml/azure-ai-ml/azure/ai/ml/operations/_job_operations.py Outdated
if _is_pipeline_child_job(job_object):
raise PipelineChildJobError(job_id=job_object.id)

from azure.ai.ml._restclient.runhistory.models import CreateRun

@saanikaguptamicrosoft saanikaguptamicrosoft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls add an entry in CHANGELOG

…a RunHistory; add CHANGELOG + api.md

- Narrow the try/except in the create_or_update shortcut to only guard the RunHistory PATCH; post-PATCH refresh/resolve failures now surface directly instead of silently falling back to the buggy MFE PUT path (addresses Copilot / saanikaguptamicrosoft review).
- Route _archive_or_restore through the same RunHistory shortcut so jobs.archive/restore work for Command/Sweep/Spark/Parallel (were previously broken for all non-Pipeline types due to the same MFE PUT round-trip bug).
- Add CHANGELOG entry for jobs.update() and the create_or_update fix.
- Add jobs.update signature to api.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants