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

stripe.Account.external_accounts still deserializes into StripeObject instead of ListObject #440

Closed
sazlin opened this issue Jul 5, 2018 · 3 comments · Fixed by #441
Closed

Comments

@sazlin
Copy link

sazlin commented Jul 5, 2018

Bug:
The recent fix for #438 does not fix the repro provided in that bug. See the same issue here:

...
account = stripe.Account.retrieve(account_id)
account_serialized = str(account)
print account_serialized  # Note that the `external accounts` key has a value of `{}`. Expecting at least an 'object' key in there with value 'list'.
account_deserialized = stripe.Account.construct_from(json.loads(account_serialized), stripe.api_key)
account_deserialized.external_accounts  # <StripeObject at 0x113deb050> JSON: {}  <-- wrong type
account_deserialized.external_accounts.create  # raises AttributeError

Repros with Stripe lib version 1.84.1
Python version 2.7.14

@ob-stripe
Copy link
Contributor

Argh. The fix only works when serializing the ListObject directly, but not when serializing an object that contains a ListObject:

>>> account = stripe.Account.retrieve('acct_...')
>>> str(account.external_accounts)
'{\n  "data": [], \n  "has_more": false, \n  "object": "list", \n  "total_count": 0, \n  "url": "/v1/accounts/acct_.../external_accounts"\n}'
>>> str(account)
'... \n  "external_accounts": {}, \n...'

We'll work on another fix. Sorry for the inconvenience @sazlin!

@sazlin
Copy link
Author

sazlin commented Jul 5, 2018

Thanks for looking. FWIW, same issue occurs for stripe.Customer.sources and probably other lists. Ideally a fix here will work for all cases.

Here's an example of how we are working around the issue right now:

def deserialize(cached_value):  # cached_value is basically str(account)
    raw_seller_account = json.loads(cached_value)
    if 'object' not in raw_seller_account['external_accounts']:
        raw_seller_account['external_accounts']['object'] = stripe.ListObject.OBJECT_NAME
    return stripe.Account.construct_from(raw_seller_account, stripe.api_key)

Update:
This workaround isn't enough. ListObject.create assumes an instance has a url key here as well:

return self.request('post', self['url'], params, headers)

@ob-stripe
Copy link
Contributor

Alright, hopefully this is fixed in 1.84.2.

>>> account = stripe.Account.retrieve('acct_...')

>>> str(account.external_accounts)
'{\n  "data": [], \n  "has_more": false, \n  "object": "list", \n  "total_count": 0, \n  "url": "/v1/accounts/acct_.../external_accounts"\n}'

>>> str(account)
'{...\n  "external_accounts": {\n    "data": [], \n    "has_more": false, \n    "object": "list", \n    "total_count": 0, \n    "url": "/v1/accounts/acct_.../external_accounts"\n  }, \n ...}'

Let me know if you're still having issues with this though!

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.

2 participants