Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Async fetch_related_object_async / fetch_event_async send "usage" as an API parameter

未关闭 适合新手
#1,948 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
90/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python

调研方向

从 stripe/_stripe_client.py 中的 raw_request 和 raw_request_async 开始,然后跟踪传递 usage 的异步事件辅助函数。针对 stripe-mock 运行提供的复现步骤,并确认异步 GET 和 POST 请求会省略内部参数 usage,同时保留调用方提供的遥测数据;为这两条路径添加或更新有针对性的客户端测试。

由索引模型根据 Issue 内容生成。

描述

What happens

StripeClient.raw_request_async does not remove the internal usage keyword from params the way raw_request does. The SDK's own event notification helpers pass usage=[...] to it, so every async fetch adds usage[0]=... to the request.

For a related object with a v1 URL the API rejects the request as an unknown parameter. Against stripe-mock:

sync:  Meter
async error: InvalidRequestError Request req_123: Request validation error: ... additional properties are not allowed

Request URLs observed with a stub HTTP client for the same notification:

sync  get https://api.stripe.com/v1/accounts/acct_123
async get https://api.stripe.com/v1/accounts/acct_123?usage[0]=fetch_related_object

fetch_event_async() has the same problem (/v2/core/events/evt_...?usage[0]=pushed_event_pull&usage[1]=pushed_event_pull_async). The request telemetry also reports ["raw_request", "async"] instead of the usage the caller passed.

What should happen

The async path should behave like the sync path: usage is consumed as telemetry and never sent to the API.

Minimal repro
import asyncio, json, stripe

client = stripe.StripeClient("sk_test_123", base_addresses={"api": "http://localhost:12111"})  # stripe-mock
payload = json.dumps({
    "id": "evt_1", "object": "v2.core.event",
    "type": "v1.billing.meter.error_report_triggered",
    "created": "2024-01-01T00:00:00Z", "livemode": False,
    "related_object": {"id": "mtr_123", "type": "billing.meter", "url": "/v1/billing/meters/mtr_123"},
})
notif = client.parse_event_notification_without_verification(payload)
notif.fetch_related_object()                        # works
asyncio.run(notif.fetch_related_object_async())     # InvalidRequestError
Root cause

In stripe/_stripe_client.py, raw_request does usage = params.pop("usage", ["raw_request"]), but raw_request_async hardcodes usage=["raw_request"] and leaves usage inside params, which are then encoded into the query string (GET) or body (POST).

Tested on master at aff846c (16.0.0).

主要语言
Python
星标
2.1k
派生
539
平均合并
3 天 5 小时
30 天内合并 PR
17

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

stripe/stripe-python 的其他 Issue

查看 stripe/stripe-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。