apply_percentage will fail if a price in the discounted items is None

Create issue
Issue #1298 open
Albert O'Connor created an issue

The code around line 633 in product/ will fail with the following exception:

work[lid] = price * percentage / 100

TypeError: unsupported operand type(s) for *: 'NoneType' and 'Decimal'


I was able figure out from the error page that the price was None, the percentage was 20 as expected.

Looking back through the calling code I saw that the item which was being purchased did have a correct price associated, but the shipping's price was currently None. I can guess that this because the error occurred after the first step in the checkout process, before a shipping method is chosen.

I was able to work around this issue by setting the discount to not apply to the shipping at all, but this is undesirable.

The self evident fixes would be to not to attempt to discount prices which are None, or give the shipping price a better default. Assuming the discount will get recalculated as needed the first approach shouldn't cause any other problems.

It is difficult for me to provide a detailed patched since I am not sure who broke the contract, should all prices not be None or should apply_percentage handle None properly?

Comments (1)

  1. Hynek Cernoch
    • changed status to open

    How to reproduce it:
    - clonesatchmo
    - only one shipping module Per piece. - create a discount with "Discount percentage: something", selected "Automatic", "Apply the discount above to shipping", "All products"
    - add a product to the cart, create an order without user login, select payment test module. OK
    - try to repeat the previous step again - "TypeError at /checkout/"

  2. Log in to comment