-
Notifications
You must be signed in to change notification settings - Fork 844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(pollers/util.go): Handle missing JSON path gracefully by using entire payload #23542
base: main
Are you sure you want to change the base?
Conversation
…load test(util_test.go): add test cases for missing and existing JSON paths
Thank you for your contribution @yyoshiki41! We will review the pull request and get back to you soon. |
@microsoft-github-policy-service agree |
@JeffreyRichter shouldn't the payload for the terminal success case always be under the |
Reproduction StepsAfter upgrading to github.com/Azure/azure-sdk-for-go/sdk/[email protected], {
endpoint := "endpoint"
req, err := runtime.NewRequest(ctx, http.MethodPost, endpoint)
if err != nil {
return nil, err
}
if err := req.SetBody(&readSeekCloser{bytes.NewReader(body)}, "application/json"); err != nil {
return nil, err
}
// Start pipeline
pipeline := c.azure.Pipeline()
resp, err := pipeline.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode >= 400 {
return nil, runtime.NewResponseError(resp)
}
// Poll until the operation is done
options := &runtime.NewPollerOptions[AnalyzeResponse]{}
poller, err := runtime.NewPoller(resp, pipeline, options)
if err != nil {
return nil, err
}
result, err := poller.PollUntilDone(ctx, &runtime.PollUntilDoneOptions{})
}
// AnalyzeResponse represents a response from the Analyze operation
type AnalyzeResponse struct {
Status string `json:"status"`
CreatedDateTime time.Time `json:"createdDateTime"`
LastUpdatedDateTime time.Time `json:"lastUpdatedDateTime"`
AnalyzeResult AnalyzeResult `json:"analyzeResult"`
} |
The guidelines are here: https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md#long-running-operations--jobs We have 4 LRO patterns: PUT, DELETE, LRO Action on resource & LRO action not on a resource. Just the LRO action patterns have a result property and yes, this property should only be set/read when the status is "success". |
I understand that only the LRO action patterns have a poller, err := runtime.NewPoller(resp, pipeline, options) Thanks. |
I wanted to kindly follow up on this pull request as it’s been pending for about a month now. Thanks! |
Sorry for the delay, I'm looking into this some more. |
We had an internal discussion, and the conclusion is that the result path must be configurable instead of hard coded to "result". I've opened #23733 to address this which should also fix your scenario. |
What
ResultHelper
attempts to extract the value at the specified JSON path.If the specified JSON path is not found in the response, the entire payload is used as the result.
Why
In #22980, JSON path extraction was introduced.
However, in Azure Document Intelligence that adopted Operation-Location header strategy, it is not included under the key payloadPath: "result". As a result, the correct output cannot be retrieved (always nil).
This fix updates the logic to use the entire response if the specified JSON path key does not exist.
Ref