Skip to content

[Py SDK] Accept paginated responses without optional totals #1321

Open

Description

@SnowboardTechie

Summary

The Python client rejects valid list and search responses when paginationInfo.totalItems or paginationInfo.totalPages is omitted. Core makes both properties optional, but the shared Python PaginatedResultsInfo requires them. Callers receive a Pydantic ValidationError before any rows can be returned.

This affects existing opportunity calls and is inherited by the awards client in #1243. The shared pagination decorator also uses total_pages to determine when to stop, so making the model fields optional alone is not enough. Accept responses without totals and handle automatic pagination safely without inventing server-reported totals.

Reproducibility

I tried multiple times and saw the bug every time

How to reproduce the bug

Run this with the Python SDK and its existing httpx dependency. No live API or credentials are required:

import httpx
from common_grants_sdk.client import Client, Config

with Client(Config(base_url="https://example.test", api_key="test-key")) as client:
    client.http.close()
    client.http = httpx.Client(
        transport=httpx.MockTransport(
            lambda request: httpx.Response(
                200,
                json={
                    "status": 200,
                    "message": "ok",
                    "items": [],
                    "paginationInfo": {"page": 1, "pageSize": 10},
                },
            )
        )
    )
    client.opportunities.list(page=1)

Actual result: two missing-field errors for paginationInfo.totalItems and paginationInfo.totalPages on Paginated[dict].

Expected result: the explicit-page call accepts the conforming response and returns an empty result. Omitted totals remain unknown rather than being treated as zero or inferred to be authoritative server counts.

The same omission was reproduced through opportunity search and the #1243 candidate's award list/search methods. Reproduction used Python 3.11 and Pydantic 2.13.5. The required fields also exist on the inspected default branch at dadae960d3077188ac4633f93e8af1f3d4404061.

Browser

Not applicable

Code of Conduct

  • I agree to follow this project's Code of Conduct

Acceptance criteria

  • Opportunity and award list/search calls accept protocol-valid responses with either or both totals omitted, including explicit-page calls. Regression tests cover each omission independently and both together.
  • Automatic pagination handles missing totals with a documented, bounded termination rule. Tests cover multiple pages, empty results, a final partial page, the configured item cap, and the existing behavior when totals are supplied.
  • Pagination models and results preserve the distinction between unknown and known totals. Serialization omits absent totals rather than emitting null or fabricating server counts, and supplied totals are validated against the protocol contract.
  • Existing parsing/error channels and pagination with supplied totals remain compatible. Document any public typing or behavior changes and verify the fix through the Python SDK checks and an installed-package consumer test.

Evidence and scope

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpy-sdkRelated to Python SDKpythonIssue or PR related to Python toolingsdkIssue or PR related to our SDKs

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions