[cognitiveservices] Unblock managed compute creation — fix misleading 202 / AuthorizationFailed errors (Task 5441745)#48096
Draft
swarupecenits wants to merge 1 commit into
Conversation
…lerate read-after-write 404 Override begin_create_or_update (sync + async) to accept the service's HTTP 202 and track the LRO by polling the compute resource (BodyContentPolling) instead of the computeOperations status endpoint that needs computeOperations/read many callers lack. Tolerates the ~15-20s read-after-write 404 window, blocks until terminal, and surfaces the compute's own provisioning error. Adds 14 unit tests; bumps to 15.0.0b4.
|
Azure Pipelines: Successfully started running 1 pipeline(s). 9 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes managed compute creation by accepting HTTP 202 and polling the compute resource directly.
Changes:
- Adds customized synchronous and asynchronous resource polling.
- Handles transient 404s and provisioning errors.
- Adds tests, changelog entry, and version bump.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
operations/_patch.py |
Implements synchronous polling workaround. |
aio/operations/_patch.py |
Implements asynchronous polling workaround. |
tests/test_computes_operations_patch.py |
Tests synchronous behavior. |
tests/test_computes_operations_patch_async.py |
Tests asynchronous behavior. |
CHANGELOG.md |
Documents the fix. |
_version.py |
Bumps version to 15.0.0b4. |
| reaches a terminal state, and surfaces a genuine provisioning failure instead of masking it. | ||
| """ | ||
|
|
||
| @distributed_trace |
| """ | ||
|
|
||
| @distributed_trace | ||
| def begin_create_or_update( |
| cls = kwargs.pop("cls", None) | ||
| polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) | ||
| lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) | ||
| kwargs.pop("continuation_token", None) |
| reaches a terminal state, and surfaces a genuine provisioning failure instead of masking it. | ||
| """ | ||
|
|
||
| @distributed_trace_async |
| """ | ||
|
|
||
| @distributed_trace_async | ||
| async def begin_create_or_update( |
| cls = kwargs.pop("cls", None) | ||
| polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) | ||
| lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) | ||
| kwargs.pop("continuation_token", None) |
Comment on lines
+98
to
+99
| if str(self._status).lower() in _TERMINAL_FAILED_STATES: | ||
| raise _compute_provisioning_error(response) |
Comment on lines
+70
to
+71
| if str(self._status).lower() in _TERMINAL_FAILED_STATES: | ||
| raise _compute_provisioning_error(response) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Work item: Task 5441745
Fixes the misleading errors users hit when creating a Cognitive Services managed compute via
ComputesOperations.begin_create_or_update(surfaced throughaz cognitiveservices account compute create).The generated SDK failed asynchronous compute creation in two ways:
202 Accepted. The service returns HTTP202for the async create, but thegenerated
_create_or_update_initialonly accepts200/201, so it raisedOperation returned an invalid status 'Accepted'.Azure-AsyncOperationheaderto
.../locations/{location}/computeOperations/{operationId}, which requiresMicrosoft.CognitiveServices/locations/computeOperations/read. Callers allowed to create a computebut not granted that read permission saw a misleading
AuthorizationFailedeven though the createsucceeded.
What this change does
Overrides
ComputesOperations.begin_create_or_update(sync + async, in_patch.py) to:202in addition to200/201.GETon the resourceURL, watching
provisioningState) viaBodyContentPolling, deliberately excluding the algorithmsthat follow the
Azure-AsyncOperation/Locationheaders. This needs onlycomputes/read(whichcallers already have) and never touches
computeOperations.GETreturns
404 "Cluster not found", so a successful create is not wrongly reported as failed (boundedgrace so a genuinely missing resource still surfaces).
properties.errors(e.g. thequota message) instead of a generic
Operation returned an invalid status 'OK'.polling=Falseescape hatch and propagate genuine non-2xx create failures.Only private helpers were added (
_ComputeResourcePolling,_compute_provisioning_error,_TERMINAL_FAILED_STATES); the public API surface is unchanged.Notes
computeOperations/readrequirement + resource read-after-write lag) is addressed.
_patch.pyre-implements the initial request send because the generated_create_or_update_initialrejects the
202; kept intentionally close to the generated code.15.0.0b3→15.0.0b4; CHANGELOG updated.Testing
tests/test_computes_operations_patch.py+..._async.py), driving the realazure-core poll loop: accept 202 · polls the resource, never
computeOperations· blocks untilterminal · tolerates the read-after-write 404 · gives up on a persistent 404 · surfaces the real
failure reason · propagates non-2xx ·
polling=False. All pass;black+pyflakesclean..result()blocks (~31s), survives the 404window, and raises the real quota error on a failed provision; invalid SKUs rejected correctly.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines
Verification :
