Opened 12 years ago
Closed 11 years ago
#23923 closed defect (bug) (duplicate)
wp_get_post_revisions returns incorrect order
Reported by: | kovshenin | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | |
Component: | Revisions | Keywords: | |
Focuses: | Cc: |
Description
When a post has multiple revisions and each revision has the exact same timestamp, wp_get_post_revisions
returns revisions in reversed order, causing wp_save_post_revision
to make a bad choice for $last_revision
(which is actually the first revision) and produce an extra revision, even if it has not been changed.
In a normal environment this doesn't happen, unless you run wp_update_post
several times in a row in under one second, so this is an edge case. This edge case causes our revisions.php tests to fail randomly, depending on whether the updates happened with the same timestamp or not.
To reproduce, try running the revisions unit tests several times in a row.
Attachments (1)
Change History (7)
#3
@
12 years ago
thanks for identifying this bug! i had noticed the intermittent unit test failures in revisions, but never figured out what was causing it. your explanation makes perfect sense.
what about just ordering by ID?
#4
@
12 years ago
Yeah, thinking we should be ordering only by ID. This is the best field to determine the "real" order for revisions.
Edit: scratch that, revisions cannot be edited, so ordering by ID will always match ordering by date. However autosaves are edited/overwritten. @kovshenin's original suggestion to order by both date and ID would work properly.
If you're having trouble reproducing this, try running 23923.reproduce.diff with
--group 23923
.An easy fix would be to order by date and ID instead of date only in
wp_get_post_revisions
, but we would need something that explicitly sets descending ordering on both columns. #17065 might have a solution.