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

Invoice.discounts sync error #1973

Closed
patroqueeet opened this issue Aug 26, 2023 · 4 comments · Fixed by #1996
Closed

Invoice.discounts sync error #1973

patroqueeet opened this issue Aug 26, 2023 · 4 comments · Fixed by #1996
Assignees
Labels

Comments

@patroqueeet
Copy link

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)
@arnav13081994 arnav13081994 self-assigned this Aug 30, 2023
@arnav13081994
Copy link
Contributor

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.

@jleclanche
Copy link
Member

@arnav13081994 sure, make a PR and i will backport it to 2.8.3

@arnav13081994
Copy link
Contributor

@jleclanche This PR will fix this issue and is already rebased on top of stable/2.8

@Biszu
Copy link

Biszu commented Mar 7, 2024

@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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants