Release 1.166.3 - #3974
Merged
Merged
Release 1.166.3#3974
Conversation
OpenAPI ChangesShow/hide changesUnexpected changes? Ensure your branch is up-to-date with |
| # discount_product resolves a paid-amount-off winner's source to price | ||
| # it and discards the line; resolving that one discount a second time | ||
| # is cheaper than threading the line out through every pricing caller. | ||
| source_line=source_line_for(best, user, [product]) if best else None, |
Contributor
There was a problem hiding this comment.
Bug: A race condition in quote_user_price may cause a paid-amount-off discount to be returned with a null source because the source line is resolved twice without locking.
Severity: MEDIUM
Suggested Fix
Refactor quote_user_price to resolve the discount and its source line in a single step. The discount_product function should return both the calculated price and the source line it used, preventing the need for a second, racy resolution via source_line_for.
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/api.py#L1323
Potential issue: A race condition exists in the `quote_user_price` function. The price
for a `paid-amount-off` discount is calculated by resolving an unconsumed source line,
but this result is discarded. The source line is then re-resolved later in the function
to be included in the API response. Between these two resolution steps, a concurrent
request could consume the same source line. This would cause the second resolution to
fail, resulting in the API response correctly showing the discount amount but
incorrectly reporting the `source` as `null`, creating a logical inconsistency for API
clients.
Also affects:
discount_sources.py:176-182
Did we get this right? 👍 / 👎 to inform future reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Chris Chudzicki
Tobias Macey
cp-at-mit