-
Notifications
You must be signed in to change notification settings - Fork 552
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
Stripe::Customer.delete_discount corrupts Stripe::Customer object #963
Comments
I believe the issue stems from: https://github.com/stripe/stripe-ruby/blob/master/lib/stripe/resources/customer.rb#L33 Here's a monkey patch that fixes the broken code above: module Stripe
class Customer < APIResource
def delete_discount
resp, opts = execute_resource_request(:delete, resource_url + "/discount")
Stripe::Discount.construct_from(resp.data, opts)
end
end
end Since I don't know if the |
@matthewbjones Thank you so much for the detailed reproduction steps and finding the line of code that is causing issues. I think the bug was introduced by this change here. We used to remove the discount on the I could confirm it quickly by modifying the test for it to this
it fails because In a way it's a simple fix, but the bug has been here for long enough that it's always problematic to make subtle changes like this in a patch release and it might need a major release for it. I'll discuss this with the other maintainers next week to decide what is the best plan of action. We might also need to add that test logic to our test suite to ensure that you can't get a an instance of class A but In the meantime, I would recommend moving away from |
@remi-stripe Thanks for the speedy and detailed reply. For context, we were previously using version We wanted to make as little changes to our codebase as possible, given the 7+ years of stability and were a bit fearful of introducing a new bug considering just how long it's been and how much of the API and Ruby code changed over the years. The migration was more straightforward than feared so that's good, mostly replacing Thanks for the information on what the Stripe team recommends in terms of how to best use the Ruby gem these days. We have a whole test suite around billing + Stripe with VCR cassettes, etc. that instills a great level of confidence that our Stripe integration works as intended the way it was written years ago. This is something we will slowly migrate to over time to make sure we don't have any breaks in functionality. Kudos to the Stripe team for allowing us to use 2013 API versions with a 2017 gem for all this time! |
`Customer#delete_discount` has been broken for some time in that it tries to re-initialize `self` (which is a customer) with a received discount response. This is incorrect and leads to various problems. Here, we redefine the return value of `delete_discount` as a discount, and have it no longer mutate the object on which is was called. We add a comment as well just to help flag some of the behavior which could potentially be confusing. Fixes #963.
`Customer#delete_discount` has been broken for some time in that it tries to re-initialize `self` (which is a customer) with a received discount response. This is incorrect and leads to various problems. Here, we redefine the return value of `delete_discount` as a discount, and have it no longer mutate the object on which is was called. We add a comment as well just to help flag some of the behavior which could potentially be confusing. Fixes #963.
`Customer#delete_discount` has been broken for some time in that it tries to re-initialize `self` (which is a customer) with a received discount response. This is incorrect and leads to various problems. Here, we redefine the return value of `delete_discount` as a discount, and have it no longer mutate the object on which is was called. We add a comment as well just to help flag some of the behavior which could potentially be confusing. Fixes #963.
Thanks for reporting and bearing with us! We've released a fix in 5.29.1. |
Introduced in version
5.0.0
, worked in prior releasesBug conditions
delete_discount
methodsave
, aStripe::InvalidRequestError ((Status 404) (Request req_0Hk4gAhb1KNnl3) No such customer: 'di_xxx')
will occurExpected
To succeed, because deleting of a discount shouldn't prevent future operations on the Stripe::Customer object. The discount does actually get deleted, it's just future calls on the
Stripe::Customer
object, likesave
, will error with an incorrect customer ID.Gem version
Broke in
5.0.0
(August 20, 2019), previous release4.24.0
(August 13, 2019) works and earlier versionsThe text was updated successfully, but these errors were encountered: