-
Notifications
You must be signed in to change notification settings - Fork 573
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
Better handling of API version mismatch when deserializing events #1450
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this approach a lot, especially since the impact on the resource itself is quite minimal. The issue is what happens the day we change the event shape a lot (which could happen)?
Crazy idea: Can we deserialize to an InternalEvent
class instead that specifically just handles the request
property and nothing else?
Yeah, we're kind of lucky here that the change can be handled like an expandable attribute. In the future, we may need to write a custom deserializer.
I'm not sure I follow. Do you mean we'd keep the existing |
I mean having an |
55c99ef
to
380ee0f
Compare
bf26d27
to
5cbccd5
Compare
Gotcha. I think a custom deserializer is a cleaner approach than an |
66d72cf
to
fda2341
Compare
@remi-stripe I've updated the PR to use a custom deserializer for event objects, so that the |
5ced76c
to
92db96e
Compare
fda2341
to
2c6e725
Compare
2c6e725
to
1f0c0b1
Compare
@remi-stripe I made another change (which I should have added as a second commit but I didn't because I'm stupid): |
/// </summary> | ||
/// <remarks> | ||
/// Note: This property is populated only for events on or after October 31, 2014. | ||
/// </remarks> | ||
[JsonProperty("api_version")] | ||
public string ApiVersion { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
realizing this might affect your version mismatch error handling no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, good point. I don't think this is going to be a huge problem in practice since EventUtility.ParseEvent
should only be used when receiving a webhook though.
[JsonProperty("livemode")] | ||
public bool Livemode { get; set; } | ||
|
||
/// <summary> | ||
/// Number of webhooks that have yet to be successfully delivered (i.e., to return a 20x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh I don't like this wording. I know it's the official API docs one but we really need to automate the comments generation at least at some point in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1000. I started looking into this, it's not a trivial problem but it's definitely doable.
r? @remi-stripe
Opening the PR for early feedback, but totally open to changes here.
As it is, this PR introduces two changes:
request
attribute as if it were expandable (it's not, but it's functionally the same thing: pre 2017-05-25,request
was a string, post 2017-05-25,request
is a hash with anid
)Stripe.EventUtility.ConstructEvent
orParseEvent
to deserialize event objects (presumably, in a webhook handler), by default the library raises an exception if the API version on the event object doesn't match the API version the library is pinned to. This is a breaking change in the sense the code that used to "work" will now throw an exception ("work" in quotes because when the API versions don't match, the deserialization may fail silently if the format of the nested object changed: older attributes returned by the API will be silently ignored, newer attributes declared in the library will benull
). This behavior can be disabled by passingthrowOnApiVersionMismatch = false
to both methodsTests fail right now because I haven't fixed them yet. I'll fix / add more tests if you think we should move forward with this change.
Tentative fix for #1402.