Skip to content

sdk-drift: fetch_markets_paginated returns total=0 (Python) vs total=undefined (TypeScript) when field is absent #843

@realfishsam

Description

@realfishsam

Drift

fetch_markets_paginated / fetchMarketsPaginated disagree on the sentinel value used for total when the server does not return that field. The Python implementation hard-codes 0 as the default, which is indistinguishable from a server-reported count of zero markets. The TypeScript implementation passes the raw value through, which becomes undefined when absent — matching the model declaration of total?: number.

TypeScript SDK

sdks/typescript/pmxt/client.ts, line 835:

return {
  data: data.data.map(convertMarket),
  total: data.total,          // undefined when absent — matches PaginatedMarketsResult.total?: number
  nextCursor: data.nextCursor,
};

sdks/typescript/pmxt/models.ts, line 234:

export interface PaginatedMarketsResult {
  data: UnifiedMarket[];
  total?: number;             // explicitly optional
  nextCursor?: string;
}

Python SDK

sdks/python/pmxt/client.py, line 814:

return PaginatedMarketsResult(
    data=[_convert_market(m) for m in data.get("data", [])],
    total=data.get("total", 0),   # BUG: hardcodes 0, not None
    next_cursor=data.get("nextCursor"),
)

sdks/python/pmxt/models.py, line 399:

@dataclass
class PaginatedMarketsResult:
    data: List[UnifiedMarket]
    total: Optional[int] = None   # model says None, code passes 0
    next_cursor: Optional[str] = None

Expected

Both SDKs should use None / undefined (not 0) when the server omits total, so callers can distinguish "server did not report a count" from "server reported zero markets". The fix in Python is total=data.get("total") (default None).

Impact

Any Python caller that checks if result.total == 0 to detect an empty result set will incorrectly treat a missing-total response as empty. Callers that guard on if result.total is not None to decide whether to display a count will receive a misleading 0.


Found by automated SDK cross-language drift audit

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions