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
Event#refresh doesn't work #928
Comments
@nightpool Thanks for the report. Can you clarify why you are using |
@remi-stripe Hi Remi, nice to meet you! Thanks for the quick response. We occasionally get out-of-order webhooks from Stripe. For example, about 5-10% of the time, we get Ideally, we'd like to use some sort of monotonically increasing Now that I spell that all out, it's possible that Event#refresh wouldn't give us what we want anyway, since the state of the included object might be "frozen" in the Event at the time it's created. The Stripe API docs say "In each case, the data hash will have an attribute called object and its value will be the same as retrieving the same object directly from the API", which doesn't provide clarity on whether the data hash is created at the time of fetch or the time of the event's creation. |
I see, so yeah in that case What you should do here is to retrieve the object associated with this event instead. So if you get a |
@remi-stripe yep! just hoping for something a little cleaner then (P.S i think you probably mean |
I would recommend just not using refresh at all here. Instead, explicitly retrieve the object yourself separately. I don't think we expect usage of But I agree on the confusing error, and we'll get this fixed! |
@remi-stripe isn't refresh identical to retrieving the object? What would the concern be about using it here? |
I personally discourage anyone from mutating objects that way. I don't think it's as explicit, you're also mutating the content of Obviously it works, but since you're asking (and for future readers) I would recommend always having your code be explicit about what you are doing so that it's easier to find all the call sites of a given method in the future. |
Ah, so the concern is about mutation? I'm using it like this: order.update!(provider_payload: event.data.object.refresh) Which seems pretty clear and unambiguous to me (especially since we don't use event later in the function) but i'm open to suggestions. |
I could probably add a |
As seen in #928, the `refresh` method doesn't work for an event class. This is because event has a field called `request`, and it ends up replacing the `request` method that it inherited from being an API resource, so when `refresh` tries to make a request, it fails because it tries to invoke it on the accessor added for the event's property. Here we give `request` a much more unique name so that it will never conflict with a property field again, and update all internal references to use the new name. We use `alias` to make the old name available for backwards compatibility reasons because its been around for so long that people are probably calling it. Fixes #928.
(Just a note that we have a fix for the specific error in #936. I was able to repro this exception and confirm the fix.) |
As seen in #928, the `refresh` method doesn't work for an event class. This is because event has a field called `request`, and it ends up replacing the `request` method that it inherited from being an API resource, so when `refresh` tries to make a request, it fails because it tries to invoke it on the accessor added for the event's property. Here we give `request` a much more unique name so that it will never conflict with a property field again, and update all internal references to use the new name. We use `alias` to make the old name available for backwards compatibility reasons because its been around for so long that people are probably calling it. Fixes #928.
As seen in #928, the `refresh` method doesn't work for an event class. This is because event has a field called `request`, and it ends up replacing the `request` method that it inherited from being an API resource, so when `refresh` tries to make a request, it fails because it tries to invoke it on the accessor added for the event's property. Here we give `request` a much more unique name so that it will never conflict with a property field again, and update all internal references to use the new name. We use `alias` to make the old name available for backwards compatibility reasons because its been around for so long that people are probably calling it. Fixes #928.
Thanks for the report @nightpool. We just released a fix for the |
The
.refresh
resource method gives an error when used on events.You can see the stack-trace below
I believe this is because the Event API object has a
request
property, which overrides the.request
method provided by https://github.com/stripe/stripe-ruby/blob/master/lib/stripe/api_operations/request.rb, whichrefresh
uses to fetch a new copy of the object:stripe-ruby/lib/stripe/api_resource.rb
Line 96 in 403f9b2
The text was updated successfully, but these errors were encountered: