Release 1.165.3 - #3940
Release 1.165.3#3940
Conversation
… even through APIs (#3909) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
OpenAPI ChangesShow/hide changesUnexpected changes? Ensure your branch is up-to-date with |
| status=status.HTTP_400_BAD_REQUEST, | ||
| ) | ||
| basket.basket_items.all().delete() | ||
| BasketDiscount.objects.filter(redeemed_basket=basket).delete() |
There was a problem hiding this comment.
Bug: The create_basket_with_products function deletes all basket discounts when ENABLE_MULTIPLE_CART_ITEMS=False but fails to re-apply existing manual discounts, causing them to be silently lost.
Severity: HIGH
Suggested Fix
Mirror the logic in the _create_basket_from_product function. Before deleting discounts, read and store any existing manually-applied discounts from the basket. After clearing the basket and adding the new product, re-apply these stored manual discounts along with any auto-apply discounts. This will ensure discount preservation consistency across different cart update flows.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: ecommerce/views/v0/__init__.py#L435
Potential issue: When `ENABLE_MULTIPLE_CART_ITEMS` is `False`, the
`create_basket_with_products` view deletes all existing discounts from a basket but does
not re-apply any manually-added discounts. The code at
`ecommerce/views/v0/__init__.py:435` calls
`BasketDiscount.objects.filter(redeemed_basket=basket).delete()`, clearing all
discounts. Unlike the similar `_create_basket_from_product` function, it lacks logic to
preserve and re-apply these discounts. This causes a user who updates their cart with a
single product to silently lose any previously applied manual discounts, resulting in an
unexpected price increase at checkout.
Did we get this right? 👍 / 👎 to inform future reviews.
Chris Patti
cp-at-mit