azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

Pagination on GetBackupProtectableItemsAsync not working (or I'm doing something wrong)

Open bzuidgeest opened this issue 1 year ago • 3 comments
trafficstars

Library name and version

Azure.ResourceManager.RecoveryServicesBackup

Query/Question

I'm trying to get all backupitems, but whatever I try I only get a single page of exactly 100 items. Is this function broken?

I tried all options on //https://learn.microsoft.com/en-us/dotnet/azure/sdk/pagination#iterate-over-pageable and I always get a single page. I know there are more then 100 items and the item I know is there is not even returned on the first and only page I get.

string filter = $"backupManagementType eq '{BackupManagementType.AzureWorkload}'"; 
            AsyncPageable<WorkloadProtectableItemResource> result = resourceGroup.GetBackupProtectableItemsAsync(vaultName, filter);



            int count = 1;
            await foreach (WorkloadProtectableItemResource item in result)
            {

                if (item.Name == $"sqldatabse;{sourceAGName};{sourceDatabaseName}")
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine($"Name: {item.Name}, ");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                else
                {
                    Console.WriteLine($"{count} Name: {item.Name}, BackupManagementType {item.Properties.BackupManagementType} WorkLoadType: {item.Properties.WorkloadType} ");
                }

                count++;
            }

            result = resourceGroup.GetBackupProtectableItemsAsync(vaultName, filter);
            count = 1;
            IAsyncEnumerator<WorkloadProtectableItemResource> enumerator = result.GetAsyncEnumerator();
            try
            {
                while (await enumerator.MoveNextAsync())
                {
                    WorkloadProtectableItemResource secret = enumerator.Current;
                    Console.WriteLine($"{count} IterateSecretsWithWhileLoopAsync: {secret.Name}");
                    count++;
                }
            }
            finally
            {
                await enumerator.DisposeAsync();
            }

            
            count = 1;
            string continuationToken = "";
            while (continuationToken != null)
            {
                result = resourceGroup.GetBackupProtectableItemsAsync(vaultName, filter, continuationToken);

                await foreach (Page<WorkloadProtectableItemResource> page in result.AsPages())
                {
                    foreach (WorkloadProtectableItemResource secret in page.Values)
                    {
                        Console.WriteLine($"{count} IterateSecretsAsPagesAsync: {secret.Name}");
                    }

                    // The continuation token that can be used in AsPages call to resume enumeration
                    Console.WriteLine("contoken: " + page.ContinuationToken);
                    continuationToken = page.ContinuationToken;
                    count++;
                }
            }

Environment

net 7.0 Vs2022 17.5.5 windows 11

bzuidgeest avatar Jan 08 '24 14:01 bzuidgeest

Thank you for your feedback. Tagging and routing to the team member best able to assist.

jsquire avatar Jan 08 '24 14:01 jsquire

Hi @bzuidgeest , Thank you for using Azure SDK for .NET. We can't repro your issue based on current information. You could get the list item like:

    await foreach (var item in resourceGroup.GetBackupProtectableItemsAsync("name"))
    {
        Console.WriteLine(item.Name);
    }

If you still could only get 100 items, I suggest you could check the payload of the response, see if there is only 100 items and one page, no nextLink value. If that's the case, you may need to check with the service team. please open an Azure support request.

HarveyLink avatar Feb 21 '24 07:02 HarveyLink

Hi @bzuidgeest. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

github-actions[bot] avatar Feb 21 '24 07:02 github-actions[bot]

Hi @bzuidgeest, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

github-actions[bot] avatar Feb 28 '24 09:02 github-actions[bot]