manage.py sync_customers broken - AttributeError: invoices
mcastle opened this issue · 5 comments
Running manage.py sync_customers is broken and throws an AttributeError: invoices.
File "/pinax/stripe/actions/invoices.py", line 134, in sync_invoices_for_customer
for invoice in customer.stripe_customer.invoices().data:
File "/stripe/stripe_object.py", line 85, in __getattr__
raise AttributeError(*err.args)
AttributeError: invoices
I first noticed this after upgrading to pinax-stripe 4.4.0 and stripe-python 2.4.0.
Reverting to pinax-stripe 4.3.1 and stripe-python 1.84.2 fixes issue.
@mcastle If you're interested, this is a quick hack we came up with to be able to support latest pinax-stripe
and stripe-python
versions: bonidjukic@80e618e
Please keep in mind that we only tested the above mentioned sync_customers
, we still have to test if this works generally.
BTW, this is the stripe-python
"deprecation" commit which seems to have introduced regressions in pinax-stripe
: stripe/stripe-python@d416e9e
@bonidjukic
Please consider creating a PR, then it should also be visible if this code is covered in tests (probably not).
The problem is that the tests mock the call out to invoices.sync_invoices_for_customer
. Or, in the tests for the function itself, that is also mocked. The mocks aren't mocking a specific version of the stripe-python library, they are mocking whatever you want them to.
Basically, a fix would involve replicating the code to fetch all the invoices for the given user, doing the same thing the removed code did: stripe/stripe-python@d416e9e#diff-0399a8a9696e3c2e5288d50b66a3c81cL30
def get_invoices_for_customer(customer):
params = {customer_id: customer.id}
invoices = Invoice.list(customer.api_key, **params)
return invoices
Here's actually how I solved it, which I also think should be backwards compatible with the previous version of the stripe-python library:
def sync_invoices_for_customer(customer):
stripe_customer = customer.stripe_customer
stripe_invoices = stripe.Invoice.list(customer=stripe_customer.id)
for invoice in stripe_invoices.data:
sync_invoice_from_stripe_data(invoice, send_receipt=False)