[wp-trac] [WordPress Trac] #59361: update_post_meta() strict checks can cause false negatives

WordPress Trac noreply at wordpress.org
Fri Sep 15 07:47:12 UTC 2023


#59361: update_post_meta() strict checks can cause false negatives
--------------------------------+------------------------------------------
 Reporter:  mukesh27            |      Owner:  (none)
     Type:  defect (bug)        |     Status:  new
 Priority:  normal              |  Milestone:  Future Release
Component:  Options, Meta APIs  |    Version:
 Severity:  normal              |   Keywords:  needs-patch needs-unit-tests
  Focuses:  performance         |
--------------------------------+------------------------------------------
 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

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59361>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list