-
Notifications
You must be signed in to change notification settings - Fork 548
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
Always return the result of APIResource#refresh in APIResource.retrieve #1473
Conversation
|
Hi @AnotherJoSmith, sorry for the friction here! We changed this due to the change in behavior for StripeClient, but we did not realize this regression would occur. Do you mind adding tests and we will get this merged. I've also made a ticket to track this internally, and will track details for
this regression as well. In the future I would recommend opening an issue and linking the PR to the issue -- we track user GH issues much more closely than user PRs! |
With the refactor of v13, there are now cases where `self` is not mutated in the call to refresh and instead a new object is returned. This change ensures that the new object is always returned by returning the result of refresh instead.
21ea965
to
5face29
Compare
@helenye-stripe Added a test (which I verified fails without my change). I also updated the README which had outdated instructions on installing stripe-mock. |
@helenye-stripe Any chance you can release a new patch version? That will unblock our ability to upgrade this gem at Shopify. |
We're releasing soon - @jar-stripe will be taking care of this. |
@AnotherJoSmith This should be out in v13.0.2! |
This is somewhat of a bug report masked as a PR, since I'm not sure what I suggested is the desired solution based on the API design of
ApiResource.refresh
. If we think this is the best solution for now, I'm happy to add tests as well.With the refactor of v13, there are now cases where
self
is not mutated in the call to refresh and instead a new object is returned. This change ensures that the new object is always returned by returning the result of refresh instead.This case happens when the else branch of this method is triggered.
stripe-ruby/lib/stripe/api_requestor.rb
Lines 236 to 244 in a2e2881
This happens if you defined a custom object that extends APIResource. For example, at Shopify we have an object like so:
The retrieve method no longer works with the method for v13, since it doesn't return the result of the API call, since
instance
is not mutated in this case.However even after the change in this PR, there is still a regression since calling
super
now returns a generic StripeObject. To be able to return an instance of our custom class, I had to change the code of retrieve to something like this:This is obviously not as clean as it was before. It's also a bit unintuitive to have a method called
#refresh
which returns a newStripeObject
instance instead of mutating the existing instance, which seems like the intent of that method.Changelog
self
object when callingAPIResource.retrieve
, now it will always return the result ofAPIResource.refresh