Description
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
- Core pagination contract:
pageandpageSizeare required,totalItemsandtotalPagesare optional. - Python response pagination model: both totals are required.
- Python pagination decorator: aggregation relies on
total_pagesand needs corresponding handling. - Found while validating [Py SDK] Add an
awardsclient resource #1243. This issue owns the shared optional-totals discrepancy, separately from [Py SDK] Add anawardsclient resource #1243's request-body pagination repair. It does not require a Core contract change or expand [Py SDK] Add anawardsclient resource #1243. - [TS SDK] Consolidate the duplicate sort and pagination param schemas #1130 owns TypeScript query/body schema consolidation, [Core] Use integer, not int32, for pagination fields #1196 owns Core integer width, and [Core] Resolve opportunity API nullability mismatches between SDKs and protocol #1192 owns opportunity nullability mismatches. None owns this Python optional-totals bug.
- This fix can proceed independently. No release milestone or publication dependency is established by this issue.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTodo
Activity
feat(py-sdk): add awards client and resource-aware filters (#1322)