Make WordPress Core

Opened 11 years ago

Closed 10 years ago

#23923 closed defect (bug) (duplicate)

wp_get_post_revisions returns incorrect order

Reported by: kovshenin's profile 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)

23923.reproduce.diff (1.0 KB) - added by kovshenin 11 years ago.

Download all attachments as: .zip

Change History (7)

#1 @kovshenin
11 years ago

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.

#2 @nacin
11 years ago

Could we also just fetch them ASC then flip them?

#3 @adamsilverstein
11 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 @azaozz
11 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.

Last edited 11 years ago by azaozz (previous) (diff)

This ticket was mentioned in IRC in #wordpress-dev by kimparsell. View the logs.


10 years ago

#6 @SergeyBiryukov
10 years ago

  • Keywords needs-patch removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

#26042 has more traction, let's move the unit test there.

Note: See TracTickets for help on using tickets.