Make WordPress Core

Opened 3 years ago

Last modified 17 months ago

#59361 new defect (bug)

update_post_meta() strict checks can cause false negatives

Reported by: mukesh27 Owned by:
Priority: normal Milestone: Future Release
Component: Options, Meta APIs Version:
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses: performance

Description

Follow up: #22192

add_post_meta( $post_id, 'key', 1 );
update_post_meta( $post_id, 'key', 1 );

The update should not work, because they are the same. However, the meta meta cache will have "1" as a string, and then it will strict compare it to 1 as an integer. Thus, an unnecessary update will run.

It is quite common to use integers and booleans directly into these functions. They should be smart enough to recognize that "1" == 1 == true and "0" == 0 == false, and that any numeric string is also equal to a properly cast integer.

The new changes need unit tests.

Ticket from which this was spun: #22189, saving navigation menus is slow.

cc. @flixos90 @spacedmonkey @joemcgill

Change History (2)

This ticket was mentioned in ​PR #8780 on ​WordPress/wordpress-develop by ​@vishalkakadiya.


17 months ago
#1

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

Details:
---

Trac ticket:
---

CC @mukeshpanchal27

#2 @vishalkakadiya
17 months ago

@mukesh27 I have raised the PR for this ticket. Can you review it? Thanks!

​https://github.com/WordPress/wordpress-develop/pull/8780

Note: See TracTickets for help on using tickets.