Description
In the Magento admin the comments history for an order is displayed in two locations - the Information tab and the Comments History tab.
The Information tab correctly sorts the comments (by created_at DESC
and entity_id DESC
)
However the Comments History tab ONLY sorts by created_at
and thus the information can be inaccurate IF there are multiple records per order at the exact same second.
If you are using the Kount module it updates the order status when the order is placed - typically in 1 second or less. Thus this module frequently creates this bug.
The status history collection queries with the correct sorting in vendor/magento/module-sales/Model/Order.php::getStatusHistoryCollection
. But that collection is later resorted in vendor/magento/module-sales/Block/Adminhtml/Order/View/Tab/History.php::getFullHistory
for the Comments History tab and function only sorts by timestamp.
usort($history, [__CLASS__, 'sortHistoryByTimestamp']);
Preconditions (*)
- 2.4.2-p2
Steps to reproduce (*)
- Ensure the database has 2 records recorded at the same timestamp (to the second) for an order in table
sales_order_status_history
- Navigate to the order in the admin
- Select the Comments History tab
Expected result (*)
- The comments would be ordered by
created_at
andentity_id
Actual result (*)
- The comments are ordered by
created_at
only
Here is the database record sorted correctly with created_at DESC
and entity_id DESC
.
mysql> SELECT entity_id, parent_id, created_at, status, comment FROM sales_order_status_history WHERE parent_id = 2225512 ORDER BY created_at DESC, entity_id DESC;
+-----------+-----------+---------------------+--------------+---------------------------------------------------------------+
| entity_id | parent_id | created_at | status | comment |
+-----------+-----------+---------------------+--------------+---------------------------------------------------------------+
| 9932939 | 2225512 | 2021-09-09 22:41:35 | complete | Vertex Invoice sent successfully. Amount: $57.90 |
| 9932246 | 2225512 | 2021-09-09 20:00:18 | picking | picking |
| 9932124 | 2225512 | 2021-09-09 19:45:31 | processing | Order status updated from Kount. |
| 9932123 | 2225512 | 2021-09-09 19:45:30 | review_kount | Kount ENS Notification: Modify status of an order by agent. |
| 9931424 | 2225512 | 2021-09-09 16:46:45 | review_kount | Order on review from Kount. |
| 9931423 | 2225512 | 2021-09-09 16:46:45 | processing | Captured amount of $661.60 online. Transaction ID: "5wxpptgs" |
+-----------+-----------+---------------------+--------------+---------------------------------------------------------------+
6 rows in set (0.00 sec)
And on the Information tab you see that the status of Processing
is correctly listed before the status of Review
.
But here on the Comments History tab you can see that the Processing
and Review
statues have been flipped.
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Activity
m2-assistant commentedon Oct 11, 2021
Hi @PromInc. Thank you for your report.
To help us process this issue please make sure that you provided the following information:
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x releaseFor more details, please, review the Magento Contributor Assistant documentation.
Please, add a comment to assign the issue:
@magento I am working on this
🕙 You can find the schedule on the Magento Community Calendar page.
📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.
🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel
✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel
m2-assistant commentedon Oct 19, 2021
Hi @engcom-Delta. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇
1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
Details
If the issue has a valid description, the labelIssue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until labelIssue: Format is valid
appears.2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add
Issue: Clear Description
label to the issue by yourself.3. Add
Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.4. Verify that the issue is reproducible on
2.4-develop
branchDetails
- Add the comment@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.- If the issue is reproducible on
2.4-develop
branch, please, add the labelReproduced on 2.4.x
.- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
5. Add label
Issue: Confirmed
once verification is complete.6. Make sure that automatic system confirms that report has been added to the backlog.
engcom-Delta commentedon Oct 19, 2021
Hi @PromInc ,


We have tested this issue on Magento 2.4 Develop latest branch , observed comments ordered by created_at and entity_id in DB.
but on UI is in different order .Kindly review once.
PromInc commentedon Oct 19, 2021
@engcom-Delta,
Thank you for the followup.
The section of the page that I'm addressing is the top half (above the Notes for this Order heading).
From your screenshot it's hard to tell the issue as Magento doesn't render the comments and the statuses are all set the same. But the top 3 records in that top section are the ones that are likely out of order.
You could test this by changing the statues in the database as follows and see what order they render in.
entity_id
:9
,status
:pending1
entity_id
:10
,status
:pending2
entity_id
:11
,status
:pending3
engcom-Delta commentedon Oct 19, 2021
Hi @PromInc,

Please find below order after changing the status in DB.
in DB:

PromInc commentedon Oct 19, 2021
@engcom-Delta,
By having the status the same for those three records you are obscuring the issue.
I'm using the Kount module which creates different statuses in the same second (
processing
thenreview
). The point of this issue isn't whether or not they show up - it's whether or not they show up in the correct order. Your screenshots don't indicate the order in which theentity_id
's show up. That's why I suggested using a differentstatus
perentity_id
to see if the history is displayed in chronological order (sorted bycreated_at
thenentity_id
). In my experience they don't.21 remaining items