For webhooks, `webhook.request` is both a method and a data attribute

Open
#825 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
api, backend

Research direction

Start by locating the StripeObject.request method and the webhook event construction path. Reproduce the difference between event.request and event["request"], then inspect related tests or compatibility expectations. Done means the webhook request data is accessible consistently without losing the method's intended behavior.

Written by the indexing model from the issue text.

Description

bug future
Describe the bug

Incoming webhook events have a request data attribute, but the event instance already has a request bound method, so we end up with a bit of a conflict. The data attribute can still be accessed with event["request"] but it feels weird to need to do that for just that one data attribute and then use dot syntax for everything else.

>>> event = stripe.Webhook.construct_event(...)

>>> event.request
<bound method StripeObject.request of <Event event id=<id_omitted> at 0x1035bb450> JSON: { ...

>>> event["request"]
<StripeObject id=<id_omitted> at 0x102e95810> JSON: {
  "id": "<id_omitted>",
  "idempotency_key": "<idempotency_key_omitted>"
}

event.request and event["request"] both returning different things is rather confusing, and it took me quite a while to figure out what was going on.

To Reproduce
  1. Construct a webhook event.
  2. Access event.request.
  3. Access event["request"].
  4. Notice that they are different.

I would probably consider this less of a "bug" and more of an oversight.

Expected behavior

The event.request method should probably be something like event._request so it doesn't conflict with the incoming data. That way I can call event.request and actually get the attribute from the body of the webhook as expected.

Code snippets

No response

OS

macOS

Language version

Python 3.9.10

Library version

stripe-python v2.76.0

API version

2020-08-27

Additional context

No response

Dominant language
Python
Stars
2k
Forks
539
Avg merge
2d 7h
Merged PRs (30d)
26

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stripe/stripe-python

All issues in stripe/stripe-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.