#52007 closed defect (bug) (fixed)
sticky_posts somehow ends up with duplicate IDs and unstickying only removes one at a time
Reported by: |
|
Owned by: |
|
---|---|---|---|
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)
#2
@
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
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
@
4 years ago
- Keywords commit added
- Owner set to peterwilsoncc
- Status changed from new to assigned
Reckon this is good to go.
4 years ago
#10
@peterwilsoncc my username is rahmohn (https://profiles.wordpress.org/rahmohn/).
peterwilsoncc commented on PR #981:
4 years ago
#12
Committed in https://core.trac.wordpress.org/changeset/50380
Thanks for the ticket! It seems like we should run
array_unique()
on thesticky_posts
option at some point here.