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

ValueError when trying to pickle customer data due to a field containing emtpy string #642

Closed
eka opened this issue Feb 12, 2020 · 2 comments

Comments

@eka
Copy link

eka commented Feb 12, 2020

Hi,

I receive a customer data from Stripe and the address_zip is an empty string, that's what I receive from Stripe... now, when I try to retrieve it from cache, due to the cache using pickle I will get the famous ValueError: You cannot set address_zip to an empty string. We interpret empty strings as None in requests.You may set...

I want to emphasize that the field comes as an empty string calling the Stripe python api.

It's easy to reproduce tho:

In [5]: new_card = stripe.Card.construct_from({'id': 'ca_test', 'address_zip': ''}, 'api_key')
   ...: pc = pickle.dumps(new_card)
   ...: card = pickle.loads(pc)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-3cbc1f7a74ed> in <module>
      1 new_card = stripe.Card.construct_from({'id': 'ca_test', 'address_zip': ''}, 'api_key')
      2 pc = pickle.dumps(new_card)
----> 3 card = pickle.loads(pc)

/usr/local/lib/python3.6/site-packages/stripe/resource.py in __setitem__(self, k, v)
    131                 "We interpret empty strings as None in requests."
    132                 "You may set %s.%s = None to delete the property" % (
--> 133                     k, str(self), k))
    134
    135         super(StripeObject, self).__setitem__(k, v)

ValueError: You cannot set address_zip to an empty string. We interpret empty strings as None in requests.You may set {
  "id": "ca_test"
}.address_zip = None to delete the property

Here is the proof of the api call from Python:

image

My workaround was to sanitize all the fields in case of empty string...
I don't know why the request returns a field with an empty string in the first case tho.

@ob-stripe
Copy link
Contributor

Hi @eka, can you share the versions of Python and stripe-python you're using? I was unable to reproduce this issue with Python 3.8.1 / stripe-python 2.42.0:

>> import pickle

>>> new_card = stripe.Card.construct_from({'id': 'ca_test', 'address_zip': ''}, 'api_key')

>>> pc = pickle.dumps(new_card)

>>> card = pickle.loads(pc)

>>> card
<Card id=ca_test at 0x10deaf7c0> JSON: {
  "address_zip": "",
  "id": "ca_test"
}

In particular, in version 1.69.0 we fixed a bug when unpickling Stripe objects with Python 3 which seems similar to what you're describing (cf. #353).

@eka
Copy link
Author

eka commented Feb 13, 2020

@ob-stripe Hi, thanks for your reply.

You are right this project is using an old version of python-stripe, thanks for the heads up.

@eka eka closed this as completed Feb 13, 2020
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

No branches or pull requests

2 participants