Skip to content

[5.x] Prevent stale order saves un-completing orders or wiping adjustments (#4398) - #4404

Merged
lukeholder merged 2 commits into
5.xfrom
bugfix/5.x-4398-stale-order-saves
Nov 4, 2026
Merged

lukeholder merged 2 commits into
5.xfrom
bugfix/5.x-4398-stale-order-saves

Conversation

@lukeholder

Copy link
Copy Markdown
Member

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. The order-after-save mutex 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 mode all) can save after a payment webhook/return request has completed the order. That stale save:

  • writes isCompleted = false, orderStatusId = null over the completed order. getIsPaid() requires isCompleted, so paidStatus becomes partial even when paid equals due, and a later request completes it again (duplicate null -> New history rows).
  • holds adjustment IDs that no longer exist, so every saveOrderAdjustment() throws OrderAdjustmentNotFoundException (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

  1. 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.
  2. Order::_saveAdjustments(): if any adjustment was not found (stale instance), skip the "delete everything not in my list" cleanup.
  3. 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

@lukeholder lukeholder changed the title Prevent stale order saves un-completing orders or wiping adjustments (#4398) [5.x] Prevent stale order saves un-completing orders or wiping adjustments (#4398) Nov 2, 2026
@lukeholder
lukeholder marked this pull request as ready for review November 4, 2026 10:02
@lukeholder
lukeholder requested a review from a team as a code owner November 4, 2026 10:02
@lukeholder
lukeholder merged commit 8f41024 into 5.x Nov 4, 2026
@lukeholder
lukeholder deleted the bugfix/5.x-4398-stale-order-saves branch November 4, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant