Repository navigation
[5.x] Prevent stale order saves un-completing orders or wiping adjustments (#4398) - #4404
Merged
Merged
Conversation
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.
Relates to #4398 (and a similar support report of paid orders losing all shipping/tax/discount adjustments).
Cause
Order::afterSave()writes the whole order from the in-memory instance with no check that it is still current. Theorder-after-savemutex only serialises saves; it does not stop an older copy overwriting a newer one. At checkout, a front-end request that loaded the order as a cart (Carts::getCart(), which force-saves with recalculation modeall) can save after a payment webhook/return request has completed the order. That stale save:isCompleted = false,orderStatusId = nullover the completed order.getIsPaid()requiresisCompleted, sopaidStatusbecomespartialeven when paid equals due, and a later request completes it again (duplicate null -> New history rows).saveOrderAdjustment()throwsOrderAdjustmentNotFoundException(swallowed since [4.x]: Internal adjustsments cache not updated after saving new adjustments? #3283), the ID list is empty, and the cleanup delete removes all of the order's adjustments, including the newly written ones.Changes
Order::beforeSave(): an order that is already completed in the DB can never be saved as incomplete. The save is refused and a warning logged.Order::_saveAdjustments(): if any adjustment was not found (stale instance), skip the "delete everything not in my list" cleanup.Carts::getCart(): don't force-save a cart that has since been completed in the DB.A proper staleness check in
afterSave()is intentionally left to a separate PR targeting 5.8.Testing
Not reproduced under real concurrency; phpstan and ecs pass. No tests added yet.
🤖 Generated with Claude Code