Make WordPress Core

Opened 17 years ago

Closed 17 years ago

#4429 closed defect (bug) (fixed)

add_option followed by update_option not always working

Reported by: yellowswordfish's profile YellowSwordfish Owned by: markjaquith's profile markjaquith
Milestone: 2.2.2 Priority: high
Severity: major Version: 2.2
Component: Administration Keywords: add_option update_option has-patch 2nd-opinion
Focuses: Cc:

Description

I have an update script that brings a plugin from any version up to the current version. Early on there is an add_option request. Later I need to add to the content so I perform a get_option, modify the content and perform an update_option. This also happens a second time in the script.
Results can vary. For some the sequence works fine. For others the final option content may only contain the final two 'update' calls having lost the original.
In tests I have just performed I ended up with two option rows (with the same option_name) - the first with the original content, the second with the two modifications combined.
I do not believe this ever happened (to my knowledge) prior to 2.2 but seems to be quite common on 2.2.
It's almost as if the subsequent calls are not pulling the original option from the cache.

Attachments (2)

add_option_trunk.diff (1.3 KB) - added by markjaquith 17 years ago.
add_option() fix for trunk
add_option_branches_2.2.diff (1.4 KB) - added by markjaquith 17 years ago.
add_option() fix for 2.2.x

Download all attachments as: .zip

Change History (8)

#1 @foolswisdom
17 years ago

  • Milestone set to 2.4 (future)

#2 @markjaquith
17 years ago

  • Milestone changed from 2.4 (future) to 2.3 (trunk)
  • Owner changed from anonymous to markjaquith
  • Status changed from new to assigned

Subscribe to Comments has been triggering this bug too. I finally nailed down the issue.

add_option() tries to erase the "notoptions" cache entry for the option too early... that is, it performs it before a get_option() call. The get_option() call marks (or re-marks) the option as "notoptions" (caches its non-existence). So now when you call update_option(), it thinks the option doesn't exist, so it adds a new one. Patches coming.

@markjaquith
17 years ago

add_option() fix for trunk

@markjaquith
17 years ago

add_option() fix for 2.2.x

#3 @markjaquith
17 years ago

  • Keywords has-patch 2nd-opinion added
  • Priority changed from normal to high
  • Severity changed from normal to major

This is a pretty critical function, so I'd appreciate a second pair of eyes on these patches.

#4 @markjaquith
17 years ago

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

(In [5788]) Properly unset notoptions cache in add_option() so that get_option() and update_option() work on the same load. fixes #4429 for trunk

#5 @markjaquith
17 years ago

  • Milestone changed from 2.3 (trunk) to 2.2.2
  • Resolution fixed deleted
  • Status changed from closed to reopened

Re-open for 2.2.2

#6 @markjaquith
17 years ago

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

(In [5789]) Properly unset notoptions cache in add_option() so that get_option() and update_option() work on the same load. fixes #4429 for 2.2.x

Note: See TracTickets for help on using tickets.