-
Notifications
You must be signed in to change notification settings - Fork 445
AttributeError on accessing Charge.refunds #1513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Worth noting that this works if |
The This is an integration support question though so I recommend reaching out to our support team if you have more questions: https://support.stripe.com/contact I do think we could improve the docstring here though so I'll flag internally! |
Hey @remi-stripe please read my response above (I think I wrote it while you were composing yours). Either way, to the best of my knowledge, accessing |
I disagree raising an error is incorrect in this case though because the property was never returned. We could support |
It certainly violates the principle of least surprise (which is that if the type signature says a property is defined, it should be defined). I only caught this bug because of manual testing, and it's certainly the class of bugs I would expect to be caught at type-checking time. I understand the need for consistency, and if that wins out, I definitely ✨get it✨. But it's certainly confusing. In other places where I've used This is the first place I've seen it just not be included at all by default and raise an Even with what you've said, the typing of |
For what it's worth, this doesn't seem to be an issue in the Go SDK: type Charge struct {
...
// A list of refunds that have been applied to the charge.
Refunds *RefundList `json:"refunds"`
...
} Go has significantly different conventions around optional fields, so probably not a perfect example, but definitely a pastability 🍝. |
In stripe-python it is what we mean with Go does have a different convention. But for example for the second case it would have I do hear you on the lack of discoverability and it's something we will continue to work on and aim to improve! |
I think this issue is definitely more than ✨discoverability✨. The convention here is not at all expected – accessing an attribute that's defined to exist should not cause an I've chosen the first approach with my own code, and we just pass around separate The second approach seems required in the more general case, but also is at odds with #1454 – how would you check without the I definitely understand that y'all have your own constraints and considerations, but the current approach feels far from ideal (it's likely to cause unanticipated runtime errors and bugs). I can imagine some alternatives like I also don't really buy your argument about Thanks for hearing me out. I hope you'll give it some thought. :^) |
I appreciate the thoughtful feedback and I definitely agree with your sentiment. Your Github issue has sparked some discussions internally on how we could approach this better at least so hopefully we can improve the types in the future to address this further than just a docstring improvement. |
Yay! Just as another piece of data, this actually did cause a bug for us today in production (I just had to fix it as I'm on call, yay! ✨) Essentially, we had this code: res = stripe.PromotionCode.list(
code=promo_code,
active=True,
expand=["data.coupon.applies_to"],
stripe_account=stripe_connect_account_id,
)
for code in res.data:
applies_to = code.coupon.applies_to
# do something with applies_to This feels even more unexpected. If I'm requesting to include the field via applies_to = code.coupon.applies_to if "applies_to` in code.coupon else None |
This one is quite interesting. My take here is that this is an API bug. If you haven't set It's likely too late to change as developers likely rely on that but I do think it's a problem with the API and not the types for stripe-python here. But I know that explaining the why doesn't really solve your problem in this case. |
Describe the bug
The typing for
Charge
indicates that there should be arefunds
property:Attempting to access it raises an
AttributeError
.To Reproduce
Fetch a charge and attempt to access it's
refunds
attribute.Expected behavior
It should work.
Code snippets
OS
macOS
Language version
Python 3.120
Library version
12.1.0
API version
Additional context
No response
The text was updated successfully, but these errors were encountered: