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()进行比较。检查异步分页单元测试,这些测试目前会 mock version.page;完成标准是异步分页等待异步页面方法,并且多页集合能够与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 分钟
- 30 天内合并 PR
- 3
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 天内回复