-
Notifications
You must be signed in to change notification settings - Fork 435
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
Fix multipart encoding of nested parameters #550
Conversation
Could we special-case this just for file upload? My inner paranoia is tingling right now with that sentence :p |
Not sure why the PR is failing on Travis for some Python versions -- I suspect a circular import issue, but I can't reproduce locally. I'll try shuffling some imports around anyway. EDIT: Fixed. |
eabbcd9
to
9ffd8f5
Compare
9ffd8f5
to
0f7d84f
Compare
@remi-stripe I've updated the implementation to only stringify values in |
Thanks for making the change. This looks great to me and I like that you explicitly tested a nested 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.
Thanks for looking at this, and awesome tests! LGTM.
Thanks both! |
Released as 2.24.1. |
r? @brandur-stripe @remi-stripe
cc @stripe/api-libraries
This one was a bit tricky. stripe-python rolls its own multipart encoder, which only supported two types of values: file-like (i.e. an object that has a
read
attribute) or strings. All other types caused an exception to be raised.So there were actually two different issues to fix:
The first issue was easily solved by calling
api_requestor._api_encode()
inMultipartDataGenerator
to flatten the parameters.To solve the second issue, I changedutil.utf_8()
to stringify all non-file-like values. This could potentially have side effects for regular form-encoding, but I'm fairly sure that's not the case: form-encoding works by passing the dictionary of flattened params tourlencode
which would stringify non-string values anyway.The second issue is solved by stringifying non-file-like values before adding them to the multipart buffer.