TokenPagination.next_page_async() makes a sync request and fails with an async http client
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
twilio/base/token_pagination.pyを読み、_get_page_async()を調べてから、issueの説明に従ってPage.next_page_async()と比較してください。現在version.pageをモックしている非同期ページネーションの単体テストを確認してください。非同期ページネーションが非同期のページメソッドをawaitし、複数ページのコレクションがAsyncTwilioHttpClientで動作すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Python
- スター
- 2.1k
- フォーク
- 821
- 平均マージ
- 9時間 33分
- マージ済み PR(30日)
- 3
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
twilio/twilio-python のほかの issue
-
Docs: "Handling Exceptions" should mention that network errors are not `TwilioRestException`対応中かも @henricop が 13 日前に担当しました。 オープン
難易度 1/5 1〜3時間 初心者へのやさしさ 90/100
twilio/twilio-python#986 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Clearer diagnostic when an API Key SID is passed without `account_sid`対応中かも @saryeljaramany が 5 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
twilio/twilio-python#985 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
AsyncTwilioHttpClient does not JSON-serialize request bodies for application/json endpoints (sync client does) → 400 on JSON-body v2 endpoints対応中かも @Steve0x2a が 77 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
twilio/twilio-python#932 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
twilio/twilio-python#930 ·
メンテナーはふだん 1 日以内に返信
-
[BUG] AsyncTwilioHttpClient.request does not use self.timeout対応中かも @Hashim1999164 が 96 日前に担当しました。 オープンtype: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
twilio/twilio-python#925 ·
メンテナーはふだん 1 日以内に返信
twilio/twilio-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
メンテナーはふだん 1 日以内に返信
-
area:cli area:security enhancement priority:medium size:small
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
RonaldHensbergen/composable-data-stack#1338 ·
メンテナーはふだん 1 日以内に返信
-
area:stdlib effort:S impact:med platform:linux type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
automated endpoint-dead needs-curation
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
almanac-data/climate-almanac#139 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
UKGovernmentBEIS/inspect_ai#6695 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信