Invoice.discounts sync error
patroqueeet opened this issue · comments
Describe the bug
AttributeError: 'str' object has no attribute 'get'
because Invoice.api_list
returns Invoice objs where the discounts
attribute is a list of discount IDs. But must be JSON Object with full data
To Reproduce
Call retry_unpaid_invoices
on Invoices with discounts applied. (Line Item Discounts, Product specific discounts)
Software versions
- Dj-Stripe version: 2.8.1
- Python version: 3.8
- Django version: 4+
- Stripe API version: 2017
- Database type and version: PSQL
** Proposed solution **
for stripe_invoice in Invoice.api_list(customer=self.id, **kwargs):
# hack: list returns discounts as id list, must be obj list.
invoice = Invoice.objects.get(id=stripe_invoice.id)
stripe_invoice = invoice.api_retrieve()
Invoice.sync_from_stripe_data(stripe_invoice, api_key=api_key)
I can confirm this is a bug. We simply need to add expand=["data.discounts"]
in the _sync_invoices()
method to fix. I am not sure if this will get fixed before 3.0
unfortunately.
@arnav13081994 sure, make a PR and i will backport it to 2.8.3
@jleclanche This PR will fix this issue and is already rebased on top of stable/2.8
@arnav13081994 Did the fix make it to 2.8.3? I'm experiencing this issue in 2.8.3 when calling Invoice.upcoming(customer=c)