[wp-trac] [WordPress Trac] #51486: The add_option function should not be able to update existing rows in the database.

WordPress Trac noreply at wordpress.org
Fri Oct 9 01:44:25 UTC 2020


#51486: The add_option function should not be able to update existing rows in the
database.
--------------------------+------------------------------
 Reporter:  khag7         |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by khag7):

 And now for a little history...

 It was 11 years ago, and `add_options` was located in `wp-
 includes/functions.php` back then.

 The clause `ON DUPLICATE KEY UPDATE` was added to the `add_option`
 function in ticket #11437 and commit [12403]

 The description in that ticket does explain why this clause exists in the
 SQL. On a busy site, you can't know whether the option exists or not
 before attempting to insert it. As such, an `INSERT` query may fail.

 Unfortunately, they solved that ticket incorrectly. The solution should
 have been that whatever piece of code was attempting to add the option
 `site_transient_timeout_theme_roots` should have been using
 `update_option` instead. This would've given them the result they wanted.
 Instead, they patched `add_option` with `ON DUPLICATE KEY UPDATE` and now
 we have a function that is intended to add and never update, but which in
 fact does update.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51486#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list