Skip to content
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

StripeObjects are unpickleable -- when statement_descriptor is None or empty string #352

Closed
hb-danny opened this issue Oct 19, 2017 · 2 comments · Fixed by #353
Closed

Comments

@hb-danny
Copy link

I'm having issues unpickling stripe objects if some of their properties are either the empty string, or None.

The following code reproduces it

ACCOUNT_STRING = 'acct_XXXXXXXXXXXXXXXX'
STRIPE_API_KEY = 'sk_test_XXXXXXXXXXXXXXXXXXXXXXXX'

import pickle
import stripe

stripe.api_key = STRIPE_API_KEY
acct = stripe.Account.retrieve(ACCOUNT_STRING)
print('acct.statement_descriptor <{}>'.format(acct.statement_descriptor))

acct.statement_descriptor = None
print('acct.statement_descriptor <{}>'.format(acct.statement_descriptor))
p = pickle.dumps(acct)
u = pickle.loads(p)

I also have this issue with raw account objects that I get back from stripe, because on most of them the acct.statement_descriptor is already the empty string, which also throws the same error.

@ob-stripe
Copy link
Contributor

Hey @danny-hb, thanks for reporting this.

I've verified that the issue happens with Python 3 but with Python 2. Apparently with Python 3, when unpickling StripeObjects the values are set via the __setitem__ method, which in our case causes an issue if any attribute had an empty string as its value (here).

Fixing this will probably require defining our own __getstate__ and __setstate__ methods on StripeObject.

@brandur-stripe
Copy link
Contributor

brandur-stripe commented Oct 20, 2017

Fix released as part of 1.69.0 (thanks @ob-stripe).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants