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

[BUG] Submit-PnPSearchQuery: RetryCount does not retry the search query and returns empty resultset #4758

Open
1 of 6 tasks
bjdekker opened this issue Feb 25, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@bjdekker
Copy link
Contributor

Reporting an Issue or Missing Feature

If you specify the -RetryCount parameter of the Submit-PnPSearchQuery and set it to anything other than 0, the query is not retried, but after 5 seconds an empty result set is returned.

Expected behavior

I expect that the query is retried the number of times specified in the -RetryCount parameter and if all retries fail, the Exception of the last retry is thrown.
Like this:
Image

Actual behavior

The query is set to be retried only once, but instead of the exception, an empty result set is returned:
Image

Steps to reproduce behavior

Run Submit-PnPSearchQuery with a query that will fail (e.g. specify a non-sortable managed property in the sort list) and the -RetryCount parameter set to anything other than 0, specify the -Verbose parameter to see what's happening.

Submit-PnPSearchQuery -Query "*" -MaxResults 10 -SortList @{"Title" = "ascending" } -RetryCount 2 -Verbose

What is the version of the Cmdlet module you are running?

2.99.146

Which operating system/environment are you running PnP PowerShell on?

  • Windows
  • Linux
  • MacOS
  • Azure Cloud Shell
  • Azure Functions
  • Other : please specify

Possible cause

I debugged the cmdlet to see what's happening and it looks like the reuse of the KeywordQuery instance is causing this. Currently it is implemented like this:

KeywordQuery keywordQuery = CreateKeywordQuery(clientFunction);
keywordQuery.StartRow = startRow;
keywordQuery.RowLimit = rowLimit;
var searchExec = new SearchExecutor(ClientContext);
// We'll always try at least once, even if RetryCount is 0 (default)
for (var iterator = 0; iterator <= RetryCount; iterator++)
{
    try
    {
        var results = searchExec.ExecuteQuery(keywordQuery);
        ClientContext.ExecuteQueryRetry();
...

Because the same KeywordQuery intance is reused throughout the loop, the query is not executed the second time, throws no Exception and simply returns an empty resulttable.

If you recreate the KeywordQuery instance for each retry iteration, it does work:

var searchExec = new SearchExecutor(ClientContext);
// We'll always try at least once, even if RetryCount is 0 (default)
for (var iterator = 0; iterator <= RetryCount; iterator++)
{
    try
    {
        KeywordQuery keywordQuery = CreateKeywordQuery(clientFunction);
        keywordQuery.StartRow = startRow;
        keywordQuery.RowLimit = rowLimit;
        var results = searchExec.ExecuteQuery(keywordQuery);
        ClientContext.ExecuteQueryRetry();
...
@bjdekker bjdekker added the bug Something isn't working label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant