[azure-ai-ml] Fix deployment_templates.get(name) resolving latest version (Bug 5402671)#47975
Conversation
…sion
deployment_templates.get(name) with no version sent the literal "latest" in the version slot, which the service treats as a (nonexistent) label rather than "highest version", causing a 404 (DeploymentTemplate {name}:latest not found). The latest version is now resolved client-side by listing the available versions and selecting the highest (the service exposes no "latest" label and no server-side ordering). get() also accepts a `label` keyword (label="latest" resolves to the latest version) mirroring models.get(), so a Model allowedDeploymentTemplates .../labels/latest reference can be resolved; unsupported labels raise a clear error. delete(name) resolves the latest version the same way.
Bug 5402671
There was a problem hiding this comment.
Pull request overview
This PR fixes an internal bug in the experimental azure-ai-ml DeploymentTemplateOperations where deployment_templates.get(name) (and delete(name)) sent the literal string "latest" in the version slot when no version was supplied. The service interprets that as a label, and since these templates only have numeric versions with no "latest" label, the call 404'd. The fix resolves the latest version client-side (list active versions, pick the highest) because the deployment-template REST surface exposes neither a latest label nor server-side ordering. get() additionally gains a label keyword to mirror models.get(). archive()/restore() inherit the fix transitively via get().
Changes:
- Added
_resolve_latest_version()helper that lists versions and selects the highest (numeric-aware sort with a deterministic string fallback), raisingResourceNotFoundErrorwhen none exist. get()now accepts a mutually-exclusivelabelkeyword (label="latest"→ latest version; other labels raise a clear error) and resolves the latest version client-side instead of sending"latest";delete()uses the same resolution.- Updated/added unit tests and a CHANGELOG entry documenting the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
sdk/ml/azure-ai-ml/azure/ai/ml/operations/_deployment_template_operations.py |
Adds _resolve_latest_version, label support and client-side latest resolution in get()/delete(). |
sdk/ml/azure-ai-ml/tests/deployment_template/unittests/test_deployment_template_operations.py |
Adds/updates tests asserting the highest version is resolved (not "latest") and label/error behavior. |
sdk/ml/azure-ai-ml/CHANGELOG.md |
Documents the get(name) 404 fix and new label keyword under 1.35.0 Bugs Fixed. |
… label parameter Adds the `label: Optional[str] = None` parameter to the DeploymentTemplate.get signature in the API surface snapshot and updates apiMdSha256 accordingly, so the API.md consistency CI check passes.
Notes
deployment_templates.get(name)with no version failed withDeploymentTemplate {name}:latest not found(404), and there was no way to resolve alabels/latestreference.get()didversion = version or "latest"and sent the literal string"latest"in the version slot. The service treats that as a label (a nickname), not "highest version". These templates have numeric versions (e.g. 1..5) with no"latest"label, so the lookup 404'd. There is also nolabel=parameter, so a Model'sallowedDeploymentTemplatesreference (.../deploymenttemplates//labels/latest) could not be resolved.latestlabel and its list endpoint has no server-side ordering (unlike Index/Prompt, which have a dedicatedget_latestendpoint).get()now also accepts alabelkeyword, mirroringmodels.get():label="latest"resolves to the latest version,versionandlabelare mutually exclusive, and any other (unsupported) label raises a clear error instead of a bare:latest not found.delete(name)had the same latentversion or "latest"bug and now resolves the latest version the same way.archive(name)/restore(name)are fixed transitively because they callget().Testing
test_get_no_version_resolves_latestandtest_delete_no_version_resolves_latest— assert the highest version is selected (not the literal"latest").test_get_label_latest_resolves_latest—label="latest"resolves to the latest version.test_get_version_and_label_raises(both supplied →ValueError) andtest_get_unsupported_label_raises(non-latestlabel →ResourceNotFoundErrornaming the label).test_get_no_versions_raises_not_found— no versions available → clearResourceNotFoundError.test_get_default_version/test_delete_default_version, which previously asserted the buggyversion == "latest", to assert the resolved highest version.azure-huggingfaceregistry:get(name)andget(name, label="latest")both return the latest version (v5),get(name, version, label)raisesValueError, andget(name, <unsupported label>)raisesResourceNotFoundError.deployment_templateunit suite passes (111 tests);blackandisortclean.Description
Fixes internal bug #5402671.
deployment_templates.get(name)no longer fails withDeploymentTemplate {name}:latest not foundwhen called without a version. Previously the literal string"latest"was sent as the version, which the service interprets as a label rather than "highest version". The latest version is now resolved client-side (list versions, pick the highest), since the deployment-template service exposes nolatestlabel and no server-side ordering.get()additionally accepts alabelkeyword (label="latest"resolves to the latest version) mirroringmodels.get(), solabels/latestreferences carried on a Model'sallowedDeploymentTemplatescan be resolved;versionandlabelare mutually exclusive and unsupported labels raise a clear error.delete(name)resolves the latest version the same way, andarchive()/restore()inherit the fix viaget().All SDK Contribution checklist:
General Guidelines and Best Practices
Verification
All checks below were run against the live
azure-huggingfaceregistry (and the in-repo unit tests), on the branch with this fix.1. Repro - the crash is gone
2. Reporter's suggested acceptance test - passing
3. In-repo unit tests - passing
Testing Guidelines