Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 21, 2025

The get_all_analyzers() method only returned the first page of results, truncating the analyzer list when subscriptions had many analyzers.

Changes

  • Pagination loop: Follow nextLink in responses until exhausted, collecting all pages into a single result
  • Circular link detection: Track visited URLs to prevent infinite loops
  • Page limit safeguard: Stop at 1000 pages (new MAX_PAGINATION_PAGES constant) to prevent runaway loops
  • Response validation: Verify value is a list before processing
  • Sanitized errors: Include only response structure keys in error messages, not potentially sensitive content

Implementation

def get_all_analyzers(self) -> Dict[str, Any]:
    all_analyzers = []
    url = self._get_analyzer_list_url(self._endpoint, self._api_version)
    visited_urls = set()
    page_count = 0
    
    while url:
        if url in visited_urls:
            raise RuntimeError(f"Circular pagination detected: {url} was already visited")
        
        visited_urls.add(url)
        page_count += 1
        
        if page_count > self.MAX_PAGINATION_PAGES:
            raise RuntimeError(f"Maximum pagination limit ({self.MAX_PAGINATION_PAGES} pages) exceeded")
        
        response = requests.get(url=url, headers=self._headers)
        self._raise_for_status_with_detail(response)
        response_json = response.json()
        
        analyzers = response_json.get("value", [])
        if not isinstance(analyzers, list):
            structure_keys = list(response_json.keys()) if isinstance(response_json, dict) else []
            raise ValueError(f"Expected 'value' to be a list, got {type(analyzers).__name__}. Response contains keys: {structure_keys}")
        
        all_analyzers.extend(analyzers)
        url = response_json.get("nextLink")
    
    return {"value": all_analyzers}

Returns the same {"value": [...]} format for backward compatibility with existing notebook code.

Original prompt

This section details on the original issue you should resolve

<issue_title>management.ipynb does not follow nextLink to enumerate all analyzers</issue_title>
<issue_description>The client code in this repo does not implement the functionality to follow nextLink when enumerating the analzyers.

See Content Understanding GA TypeSpec here: https://github.com/Azure/azure-rest-api-specs/tree/main/specification/ai/ContentUnderstanding

When there are many analyzers in a subscription, we will only enumerate the first part, and never get to the rest.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Nov 21, 2025
Copilot AI and others added 2 commits November 21, 2025 00:31
Co-authored-by: yungshinlintw <14239352+yungshinlintw@users.noreply.github.com>
… validation

Co-authored-by: yungshinlintw <14239352+yungshinlintw@users.noreply.github.com>
Copilot AI and others added 2 commits November 21, 2025 00:37
…messages

Co-authored-by: yungshinlintw <14239352+yungshinlintw@users.noreply.github.com>
Co-authored-by: yungshinlintw <14239352+yungshinlintw@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix management.ipynb to follow nextLink for analyzers Implement nextLink pagination in get_all_analyzers Nov 21, 2025
Copilot AI requested a review from yungshinlintw November 21, 2025 00:42
Copilot finished work on behalf of yungshinlintw November 21, 2025 00:42
@yungshinlintw yungshinlintw merged commit 2cc8a44 into main Nov 21, 2025
1 check passed
@yungshinlintw yungshinlintw deleted the copilot/fix-nextlink-analyzers-enumeration branch November 21, 2025 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

management.ipynb does not follow nextLink to enumerate all analyzers

3 participants