Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#25015 closed defect (bug) (fixed)

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

Reported by: jdgrimes's profile jdgrimes Owned by: nacin's profile 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 years ago.
First pass at this. Moves the cache updating to inside the if ( $result ) blocks.
25015.diff (7.2 KB) - added by nacin 11 years ago.

Download all attachments as: .zip

Change History (8)

#1 @jdgrimes
11 years 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.

#2 @SergeyBiryukov
11 years ago

  • Milestone changed from Awaiting Review to 3.7

@jdgrimes
11 years ago

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

#3 @jdgrimes
11 years 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.

#4 @nacin
11 years ago

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

#5 @nacin
11 years ago

  • Keywords commit added

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

@nacin
11 years ago

#6 @nacin
11 years 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.