WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 12 months 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)

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

Download all attachments as: .zip

Change History (7)

@kovshenin2 years ago

comment:1 @kovshenin2 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.

comment:2 @nacin2 years ago

Could we also just fetch them ASC then flip them?

comment:3 @adamsilverstein2 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?

comment:4 @azaozz2 years ago

Yeah, thinking we should be ordering only by ID. This is the best field to determine the "real" order.

Version 0, edited 2 years ago by azaozz (next)

comment:5 @ircbot12 months ago

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

comment:6 @SergeyBiryukov12 months 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.