TokenPagination.next_page_async() makes a sync request and fails with an async http client

Offen Anfängerfreundlich
#976 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@sebxt arbeitet bereits daran.

Seit 19.10.2026.

  • #977 von @sebxt — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
82/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
api

Rechercherichtung

Lies twilio/base/token_pagination.py und untersuche _get_page_async(). Vergleiche die Funktion anschließend wie im Issue beschrieben mit Page.next_page_async(). Prüfe die Unit-Tests für asynchrone Paginierung, die derzeit version.page mocken; das Ziel ist erreicht, wenn die asynchrone Paginierung auf die asynchrone Seitenmethode wartet und eine mehrseitige Sammlung mit AsyncTwilioHttpClient funktioniert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

What happens

TokenPagination._get_page_async() (used by next_page_async() and previous_page_async()) calls the synchronous self._version.page(...) instead of awaiting self._version.page_async(...).

With AsyncTwilioHttpClient, the sync path calls http_client.request(...), which is a coroutine function, so the page constructor receives an unawaited coroutine and raises:

AttributeError: 'coroutine' object has no attribute 'status_code'

This breaks stream_async() / list_async() for every resource that uses token pagination (for example memory.v1 stores, profiles, traits, observations and insights.v3 query jobs) as soon as a second page is needed. The first page loads, then iteration crashes. Python also warns that the coroutine was never awaited.

What should happen

The async helper should await self._version.page_async(...), the same way Page.next_page_async() awaits request_async.

Minimal repro

import asyncio
from twilio.http.async_http_client import AsyncTwilioHttpClient
from twilio.rest import Client

async def main():
    client = Client(account_sid, auth_token, http_client=AsyncTwilioHttpClient())
    async for store in await client.memory.v1.stores.stream_async(page_size=1):
        print(store)

asyncio.run(main())

Any collection with more than one page fails after the first page.

Root cause

twilio/base/token_pagination.py, _get_page_async():

response = self._version.page(method="GET", uri=self._uri, params=self._params)

The existing async unit tests mock version.page (the sync method), so they pass even though the real async client path is broken.

Vorherrschende Sprache
Python
Sterne
2.1k
Forks
821
Ø Merge
9 Std. 33 Min.
Gemergte PRs (30 T.)
3

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus twilio/twilio-python

Alle Issues in twilio/twilio-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.