WordPress.org

Make WordPress Core

Opened 11 months ago

Closed 9 months ago

#25015 closed defect (bug) (fixed)

Options cache updated by update_option() and add_option() even on failure

Reported by: jdgrimes Owned by: nacin
Milestone: 3.7 Priority: normal
Severity: normal Version: 2.2
Component: Cache API Keywords: has-patch commit
Focuses: Cc:

Description

The add_option() and update_option() functions both update the 'alloptions' cache before performing the insert/update query on the database. It is therefore possible to do the following:

add_option( 'test_option', 'foo' ); // Lets say this fails.
$option = get_option( 'test_option' ); // $option == 'foo' !

But now if we attempt to delete or update the option, we can't:

var_dump( delete_option( 'test_option' ) ); // bool(false)
var_dump( update_option( 'test_option', 'bar' ) ); // bool(false)

This was introduced in [4855].

Attachments (2)

25015.patch (2.9 KB) - added by jdgrimes 11 months ago.
First pass at this. Moves the cache updating to inside the if ( $result ) blocks.
25015.diff (7.2 KB) - added by nacin 10 months ago.

Download all attachments as: .zip

Change History (8)

comment:1 jdgrimes11 months ago

  • Summary changed from 'alloptions' cache updated by update_option() and add_option() even on failure to Options cache updated by update_option() and add_option() even on failure

This does not only affect the 'alloptions' pseudo-option, it affects any option.

comment:2 SergeyBiryukov11 months ago

  • Milestone changed from Awaiting Review to 3.7

jdgrimes11 months ago

First pass at this. Moves the cache updating to inside the if ( $result ) blocks.

comment:3 jdgrimes11 months ago

  • Keywords has-patch added

That patch moves the cache updating to inside of the if-success blocks for these two functions. I'm not sure if that is the best approach. Should we be invalidating the cache in some way if the add/update queries fail, or should we assume that the cache is still reliable? This patch does the latter.

comment:4 nacin11 months ago

  • Owner set to nacin
  • Status changed from new to accepted

comment:5 nacin10 months ago

  • Keywords commit added

The patch on #24933 handles this. Please review! Let's leave this ticket open, though, and close them out together.

nacin10 months ago

comment:6 nacin9 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 25664:

When queries fail in option functions, bail before setting cache.

Standardize variables so things are less confusing.

fixes #25015.

Note: See TracTickets for help on using tickets.