WordPress.org

Make WordPress Core

#21327 closed defect (bug) (fixed)

No default value is set for $group in WP_Object_Cache for the decr method

Reported by: bananastalktome Owned by: nacin
Milestone: 3.5 Priority: normal
Severity: normal Version:
Component: Cache API Keywords: has-patch
Focuses: Cc:

Description

Unlike incr and other methods on WP_Object_Cache, decr does not do a check to see if $group is empty to set it to 'default'. This is problematic when using wp_cache_decr() since the result is that set cache with wp_cache_set (which has $group set as 'default') is not decremented.

Patch included, but not sure if this should be classified 'normal' or 'major'. Unit tests still appear to pass, but more testing probably useful.

Attachments (2)

cache_decr_fix.patch (457 bytes) - added by bananastalktome 21 months ago.
cache_delete_fix.patch (757 bytes) - added by bananastalktome 21 months ago.

Download all attachments as: .zip

Change History (9)

comment:1 nacin21 months ago

  • Milestone changed from Awaiting Review to 3.5

Even low severity would be fine — this really only occurs if you use the method improperly by explicitly passing false, null, "", etc., which I imagine would result in a notice when it is used as a key.

comment:2 bananastalktome21 months ago

@nacin the problem is more with the wrapper wp_cache_decr, which passes an empty string as the group param to the decr method on global $wp_object_cache. So, for example, wp_cache_decr("dog", 1) would result in the grouping being set as an empty string rather than "default". I might be wrong, so please correct me if I am :)

comment:3 nacin21 months ago

Ah ha. Well, still only happens if you use wp_cache_decr() without a group. Always been broken, and not used in core. Good candidate for unit tests + patch.

comment:4 bananastalktome21 months ago

Ah, ok. Well a request for just that is in the unit-tests trac (#UT110). I'm working on tests for this now, and hopefully putting up a patch soon.

Last edited 21 months ago by bananastalktome (previous) (diff)

comment:5 nacin21 months ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In [21294]:

If $group is empty in WP_Object_Cache::decr(), consider it to be 'default'.

This is consistent with the rest of the cache methods wrapped by
functions; the functions pass an empty string by default, hence
the need for this check.

props bananastalktome.
fixes #21327.

comment:6 bananastalktome21 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Another issue found from the unit tests for these functions (#UT110), which is that the profiles of wp_cache_delete and WP_Object_Cache::delete() are different. wp_cache_delete is missing the optional third force parameter.

Patch added to add this as well (or should this be a separate ticket?)

Last edited 21 months ago by bananastalktome (previous) (diff)

comment:7 nacin21 months ago

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

wp_cache_delete() doesn't have a force parameter because there is nothing to "force". Same with wp_cache_get(). These parameters are only helpful with persistent caching backends.

Note: See TracTickets for help on using tickets.