-
Notifications
You must be signed in to change notification settings - Fork 438
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
StripeObject: only add changed values to _unsaved_values #372
Conversation
It would still trigger an update for stripe-python/tests/api_resources/abstract/test_updateable_api_resource.py Lines 137 to 144 in 1751c91
I've also found https://github.com/blueyed/stripe-python/blob/1751c911b497c37cb60bdf74eeb4073b04ef423c/tests/api_resources/abstract/test_updateable_api_resource.py#L301-L306, which seems even to be incorrect?! Doesn't it empty |
Hey @blueyed, thanks a lot for the contribution! This looks very promising.
So, no, although I can see why you'd think so! We mock >>> list(stripe.api_requestor._api_encode({'metadata': {}}))
[] I agree it would be better and clearer if |
stripe/stripe_object.py
Outdated
@@ -237,7 +238,9 @@ def serialize(self, previous): | |||
elif isinstance(v, stripe.api_resources.abstract.APIResource): | |||
continue | |||
elif hasattr(v, 'serialize'): | |||
params[k] = v.serialize(previous.get(k, None)) | |||
child = v.serialize(previous.get(k, None)) | |||
if child: |
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'm not sure if it's possible in practice, but in theory serialize
could return an empty string ""
to unset the entire attribute, and because empty strings are falsey in Python this would get ignored. It might be better to explicitly compare the returned value to an empty dict.
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.
Makes sense.
Should have a test for it then, too.
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.
if it's possible in practice
The two internal serialize
methods will return a dict always, so it is unlikely to come from there.
Added a test with a specialized StripeObject, which is likely what you had in mind?!
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.
Yes, exactly. Thanks again!
I left a comment, but generally this looks pretty great to me! r? @deontologician-stripe Do you mind taking a look at this? |
I am +1 on this. I wish we could do the checking for |
r? @ob-stripe To approve after the test you mentioned in the comment is added |
lgtm |
@dpetrovics-stripe (dev-platform run, feel free to re-assign) Mind merging this and releasing a version? Thanks! |
No description provided.