pinax / pinax-stripe-light

a payments Django app for Stripe
MIT License
684 stars 285 forks source link

Stripe 2.3.0 Webhooks #579

Closed dmcmulle closed 6 years ago

dmcmulle commented 6 years ago

Issue Summary

I have pinax-stripe 4.3.0 installed alongside stripe 2.3.0 (as specified in setup.py is >=1.7.9)

Since updating packages, we have received multiple errors on the webhook syncing with our Django application.

We've had hundreds of this error occur in the last 24 hours.

AttributeError
module 'stripe' has no attribute 'StripeObjectEncoder'
pinax/stripe/webhooks.py in validate at line 101
        )
        self.event.validated_message = json.loads(
            json.dumps(
                evt.to_dict(),
                sort_keys=True,
 >>>            cls=stripe.StripeObjectEncoder
            )
        )

It appears that the StripeObjectEncoder may have been deprecated? As I saw in this:

class StripeObjectEncoder(util.json.JSONEncoder):

    def __init__(self, *args, **kwargs):
        warnings.warn(
            '`StripeObjectEncoder` is deprecated and will be removed in '
            'version 2.0 of the Stripe bindings.  StripeObject is now a '
            'subclass of `dict` and is handled natively by the built-in '
            'json library.',
            DeprecationWarning)
        super(StripeObjectEncoder, self).__init__(*args, **kwargs)

Steps to Reproduce

Install pinax-stripe 4.3.0 with stripe 2.3.0

Attempt to sync via webhook (any Django management command will also cause similar errors to occur)

What were you expecting to happen?

When running python manage.py sync_customers, we also receive this message on prod:

Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.6/site-packages/stripe/stripe_object.py", line 83, in __getattr__
    return self[k]
  File "/app/.heroku/python/lib/python3.6/site-packages/stripe/stripe_object.py", line 122, in __getitem__
    raise err
  File "/app/.heroku/python/lib/python3.6/site-packages/stripe/stripe_object.py", line 111, in __getitem__
    return super(StripeObject, self).__getitem__(k)
KeyError: 'invoices'

What actually happened?

As a temporary fix, it seems setting stripe to version 1.84.2 (the last version before StripeObjectEncoder was deprecated) seems to have temporarily solved this issue.

blueyed commented 6 years ago

Fixed in https://github.com/pinax/pinax-stripe/pull/574.

blueyed commented 6 years ago

pinax-stripe is not compatible with stripe 2.0.

@paltman Please either get a fixed version released, or pin the stripe dependency.

blueyed commented 6 years ago

https://github.com/pinax/pinax-stripe/issues/578

paltman commented 6 years ago

Thanks to @blueyed you now have two paths forward.

If you wanted to stay with pre-2.0 release of the underlying python-stripe library, you can add pinax-stripe==4.3.1 to your requirements file. If you want the latest/greatest of the python-stripe library, you can add pinax-stripe==4.4.0.