Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#52007 closed defect (bug) (fixed)

sticky_posts somehow ends up with duplicate IDs and unstickying only removes one at a time

Reported by: archon810's profile archon810 Owned by: peterwilsoncc's profile peterwilsoncc
Milestone: 5.7 Priority: normal
Severity: normal Version: 5.5.3
Component: Posts, Post Types Keywords: has-patch has-unit-tests commit
Focuses: Cc:

Description

Hi all,

Somehow we ran into this bug on production where the sticky_posts array ended up with duplicate IDs that were stickied, and unstickying only removed the same ID one at a time instead of all of them at once, so unstickying kept the post stickied until it was unstickied enough times to clear the array.

For example, this is how I found sticky_posts:

a:3:{i:1;i:744381;i:2;i:725382;i:3;i:725382;}

Note that 725382 is duplicated. Unstickying once did this:

a:2:{i:0;i:744381;i:1;i:725382;}

How we got to the duplicate ID state, I cannot say (perhaps that's a separate bug), but solution here is to not exit the loop when the ID is reached and removed and instead keep going till the end.

Change History (13)

#1 @SergeyBiryukov
4 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 5.7

Thanks for the ticket! It seems like we should run array_unique() on the sticky_posts option at some point here.

#2 @archon810
4 years ago

This just happened again. The fix should be really simple, can we give this one a kick please?

This ticket was mentioned in PR #981 on WordPress/wordpress-develop by Rahmon.


4 years ago
#3

  • Keywords has-patch has-unit-tests added; needs-patch removed

This change tries to prevent duplicate post IDs in the sticky_posts option.

Trac ticket: https://core.trac.wordpress.org/ticket/52007

Rahmon commented on PR #981:


4 years ago
#4

Hi @peterwilsoncc

Thank you for your review. I'll take a look.

Rahmon commented on PR #981:


4 years ago
#5

@peterwilsoncc I've split up the assertions a little. :grimacing:

peterwilsoncc commented on PR #981:


4 years ago
#6

These tests look way more focused, thank you.

It might be good to use a data provider but I can push those as they are a little fiddly.

Code changes and tests look good to me.

peterwilsoncc commented on PR #981:


4 years ago
#7

@Rahmon I've pushed some minor changes to the tests in https://github.com/WordPress/wordpress-develop/pull/981/commits/64c4b7fa599a0da29ccee3187d88c6dc194be15f

  • Used a data provider where possible.
  • Added tests to make sure the database isn't updated unnecessarily
  • Added docblocks too

peterwilsoncc commented on PR #981:


4 years ago
#8

@Rahmon Oh, meant to ask: what is your wordpress.org username so i can give props on the ticket?

#9 @peterwilsoncc
4 years ago

  • Keywords commit added
  • Owner set to peterwilsoncc
  • Status changed from new to assigned

Reckon this is good to go.

Rahmon commented on PR #981:


4 years ago
#10

@peterwilsoncc my username is rahmohn (https://profiles.wordpress.org/rahmohn/).

#11 @peterwilsoncc
4 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 50380:

Posts/Post Types: Prevent duplicates in sticky posts option.

In unstick_post() if a post ID is duplicated in the sticky_posts option remove all instances.

In both stick_post() and unstick_post() check for duplicate IDs already stored in the sticky_post option and remove them if the option is updated.

Props rahmohn, archon810.
Fixes #52007.

#13 @SergeyBiryukov
4 years ago

In 50384:

Tests: Rename stick_post() and unstick_post() tests for a bit more clarity.

Add missing DocBlock for test_unstick_post_updates_option().

Follow-up to [50380].

See #52007.

Note: See TracTickets for help on using tickets.