Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yyoshiki41
Copy link

@yyoshiki41 yyoshiki41 commented Oct 3, 2024

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


  • The purpose of this PR is explained in this or a referenced issue.
  • The PR does not update generated files.
  • Tests are included and/or updated for code changes.
  • Updates to module CHANGELOG.md are included.
  • MIT license headers are included in each file.

…load

test(util_test.go): add test cases for missing and existing JSON paths
@github-actions github-actions bot added Azure.Core Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Oct 3, 2024
Copy link

github-actions bot commented Oct 3, 2024

Thank you for your contribution @yyoshiki41! We will review the pull request and get back to you soon.

@yyoshiki41
Copy link
Author

@microsoft-github-policy-service agree

@jhendrixMSFT
Copy link
Member

jhendrixMSFT commented Oct 3, 2024

@JeffreyRichter shouldn't the payload for the terminal success case always be under the result property in the status monitor JSON response? I thought that was the contract.

@yyoshiki41
Copy link
Author

yyoshiki41 commented Oct 3, 2024

Reproduction Steps

After upgrading to github.com/Azure/azure-sdk-for-go/sdk/[email protected], result is always nil when executing the following pseudo code.

{
	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"`
}

@JeffreyRichter
Copy link
Member

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".

@yyoshiki41
Copy link
Author

@JeffreyRichter @jhendrixMSFT

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 result property, which should only be set or read when the status is “success.”
Does this mean that Azure Document Intelligence doesn’t fall under these LRO action patterns, and therefore, the result property wouldn’t apply in this case? If so, should we avoid using runtime.NewPoller in Document Indelligence?

	poller, err := runtime.NewPoller(resp, pipeline, options)

Thanks.

@yyoshiki41
Copy link
Author

@JeffreyRichter @jhendrixMSFT

I wanted to kindly follow up on this pull request as it’s been pending for about a month now.
Could you please let me know if there’s anything further I can address to help move this forward?
I’d be happy to make any adjustments as needed to expedite the review process.

Thanks!

@jhendrixMSFT
Copy link
Member

Sorry for the delay, I'm looking into this some more.

@jhendrixMSFT
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Core Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants