WordPress.org

Make WordPress Core

Opened 6 months ago

Closed 4 months ago

Last modified 4 months 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 Owned by: 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
6 months 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 months 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 months ago

  • 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

#4 @prbot
4 months ago

Rahmon commented on PR #981:

Hi @peterwilsoncc

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

#5 @prbot
4 months ago

Rahmon commented on PR #981:

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

#6 @prbot
4 months ago

peterwilsoncc commented on PR #981:

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.

#7 @prbot
4 months ago

peterwilsoncc commented on PR #981:

@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

#8 @prbot
4 months ago

peterwilsoncc commented on PR #981:

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

#9 @peterwilsoncc
4 months ago

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

Reckon this is good to go.

#10 @prbot
4 months ago

Rahmon commented on PR #981:

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

#11 @peterwilsoncc
4 months 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 months 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.