[v10] Fix setState() silent failure causing state/status desynchronization#3290
Open
acourtiol wants to merge 1 commit into
Open
[v10] Fix setState() silent failure causing state/status desynchronization#3290acourtiol wants to merge 1 commit into
acourtiol wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a fallback mechanism in the setState method to resolve order states directly from the database when preferred state mappings are unavailable, preventing state/status desynchronization. Feedback suggests improving logging consistency by using the getOrderContext method and ensuring deterministic results in the fallback query by ordering by the is_default flag.
86f3e42 to
ed449a9
Compare
When setState() cannot find a matching state in the $possibleStates
array (from STATE_TRANSITION_MATRIX), it now falls back to a direct
lookup in sales_order_status_state for the given status, preferring
the default state mapping. This prevents the order state from being
permanently stuck at its previous value (typically pending_payment)
while the status advances through the order lifecycle.
The fallback query uses addOrder('is_default', 'DESC') to prefer
the default state when a status maps to multiple states, and
setPageSize(1) to limit the SQL query at the database level.
Uses getOrderContext() for consistent logging with the rest of the
module.
Fixes Adyen#3288
ed449a9 to
95561f1
Compare
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.
This is the v10 equivalent of #3289 (submitted against main-9).
What this PR does
Adds a fallback in
Helper/Order.php::setState()so that when the$possibleStatesconstraint (fromSTATE_TRANSITION_MATRIX) doesn't produce a match, the method falls back to a direct lookup insales_order_status_statefor the given status. This prevents the order state from being permanently stuck at its previous value while the status advances.Why this is needed
Currently,
setState()iterates$possibleStatesand if no match is found, it logs a notification and returns without changing the state. Meanwhile, the status was already updated by the caller (addStatusHistoryCommentcallssetStatus()internally). This leaves the order with a mismatched state/status that never gets corrected.On our production instance, this resulted in 63,805 orders with
state=pending_payment+status=complete/closedsince 2021. The code is identical in v9.20.13 and v10.10.0.How it works
After the existing
$possibleStatesloop fails, the fix does a direct lookup insales_order_status_state:The preferred
STATE_TRANSITION_MATRIXstates are still tried first. The fallback only activates when no preferred match is found.Related