DataClient.wait_asset raises "Maximum number of attempts reached" when the last poll returns an active asset
评估
调研方向
阅读 planet/clients/data.py 中的轮询循环,并将其与 OrdersClient.wait 进行比较;issue 指出后者能正确处理尝试次数计数。复现 max_attempts=2 的情况,其中第二个响应的状态为 active,并检查在引发次数上限错误之前是否会检查最后获取的状态。完成标准是:返回最后一个 active 响应,且回调收到 active;如果 asset 达到上限时仍处于 inactive 状态,则引发错误。
由索引模型根据 Issue 内容生成。
描述
What happens
DataClient.wait_asset (and Planet().data.wait_asset and planet data asset-wait, which call it) fetches the asset on each attempt but only checks the status at the top of the next loop iteration. When the asset becomes active on the final allowed poll, the loop ends on the attempt count, the fresh status is never looked at, and a ClientError("Maximum number of attempts (N) reached.") is raised. The callback is also never called with active.
What should happen
If the last poll returns active, wait_asset should return that asset, the same as it does when activation finishes on any earlier poll. The error should only be raised when the asset is still not active after max_attempts polls.
Minimal repro
import asyncio, copy, httpx, respx
from planet import DataClient, Session, Auth
URL = "https://example.test/asset"
asset = {"_links": {"_self": URL}, "status": "activating"}
active = copy.deepcopy(asset)
active["status"] = "active"
@respx.mock
async def main():
respx.get(URL).side_effect = [
httpx.Response(200, json=asset),
httpx.Response(200, json=active),
]
async with Session(auth=Auth.from_key("x")) as sess:
cl = DataClient(sess)
print(await cl.wait_asset(asset, delay=0, max_attempts=2))
asyncio.run(main())
Output:
planet.exceptions.ClientError: Maximum number of attempts (2) reached.
The second and last poll returned "status": "active".
Root cause
In planet/clients/data.py, the loop condition is while not max_attempts or num_attempts < max_attempts, and the new asset is fetched at the bottom of the loop body after num_attempts += 1. When num_attempts reaches max_attempts the loop exits before the status check at the top runs, and the check after the loop only looks at num_attempts. OrdersClient.wait does not have this problem because it polls at the top of the loop and checks the state before counting the attempt.
- 主要语言
- Python
- 星标
- 300
- 派生
- 100
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
planetlabs/planet-client-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
planetlabs/planet-client-python#1230 ·
-
better-testing
难度 2/5 1-3 小时 新手友好度 65/100
planetlabs/planet-client-python#1110 ·
-
Broken examples in order_request and subscription_request docstrings, async SDK guide and CLI tips未关闭
难度 2/5 1-3 小时 新手友好度 35/100
planetlabs/planet-client-python#1231 ·
-
FeaturesClient list_items does not support filtering可能已有人在做 @steps-re 于 105 天前认领。 未关闭proposal
难度 3/5 1-2 天 新手友好度 65/100
planetlabs/planet-client-python#1221 ·
-
FeaturesClient does not implement Update Feature可能已有人在做 @tbarsballe 于 134 天前认领。 未关闭proposal
难度 3/5 1-2 天 新手友好度 57/100
planetlabs/planet-client-python#1214 ·
查看 planetlabs/planet-client-python 的全部 Issue
相似的 Issue
-
documentation
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复
-
good first issue module-baseline needs triage ux
难度 2/5 1-3 小时 新手友好度 82/100
darnitdevorg/darnit#650 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
nyjc-computing/campus#938 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
nf-osi/nf-metadata-dictionary#1027 ·
维护者通常 1 天内回复
-
bug documentation
难度 1/5 1 小时以内 新手友好度 92/100
qatrackplus/qatrackplus#913 ·
维护者通常 3 天内回复