[wp-trac] [WordPress Trac] #52345: Transient with expiration never expires when storing expiration failed

WordPress Trac noreply at wordpress.org
Sat Jan 23 23:24:23 UTC 2021


#52345: Transient with expiration never expires when storing expiration failed
-------------------------------------------------+-------------------------
 Reporter:  mennoll                              |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
                                                 |  Review
Component:  Options, Meta APIs                   |     Version:  2.8
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests needs-      |     Focuses:
  refresh                                        |
-------------------------------------------------+-------------------------
Changes (by peterwilsoncc):

 * keywords:  has-patch has-unit-tests => has-patch has-unit-tests needs-
     refresh
 * version:  5.6 => 2.8


Comment:

 For transients set without a timeout (ie, the `$expriation` parameter in
 `set_transient()` is zero or another falsy value) the timeout option is
 not set. This means the above approach would end up deleting permanent
 transients when getting them.

 For expiring transients, an alternative approach would be a similar
 approach in `set_transient()`: if the transient value option is saved
 successfully but the timeout option fails to save then the value is
 deleted.

 In very simplified code:

 {{{#!php
 <?php
 $timeout_result = add_option( $transient_timeout, time() + $expiration,
 '', 'no' );
 if ( $timeout_result ) {
     $result = add_option( $transient_option, $value, '', 'no' );
     if ( ! $result ) {
         // delete both options.
     }
 }
 }}}

 Due to the way `set_transient()` works, the simplified code would need to
 be repeated a couple of times and some modification for the calls to
 `update_option()` as it will return `false` if the new value matches the
 old.

 This seems like a pretty edge-case bug so I am not sure if the additional
 code provides much benefit, is it something you have hit frequently?

 It looks like this has been the case since transients where first
 introduced in 2.8, so I've updated the version to reflect that.

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


More information about the wp-trac mailing list