Make WordPress Core

Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#22807 closed defect (bug) (fixed)

Updating a non-expiring transient with a new expiry date does not make it expire

Reported by: bersbers Owned by: nacin
Priority: normal Milestone: 3.9
Component: Options, Meta APIs Version: 3.4.2
Severity: normal Keywords: dev-feedback
Cc: Focuses:

Description

Consider this:
set_transient( 'Bug', 'v1');
set_transient( 'Bug', 'v2', 10 );

The second line will update 'Bug' with 'v2', but will not set autoload to 'no'. Hence, 'Bug' does never expire, and you can get its value 'v2' infinitely using

echo get_transient( 'Bug' );

Attachments (5)

option.diff​ (1.3 KB ) - added by shahpranaf 13 years ago.
Patch for Updating a non-expiring transient with a new expiry date
option.2.diff​ (927 bytes ) - added by sandyr 13 years ago.
The correct diff which passes the current unit tests
transient.diff​ (1019 bytes ) - added by sandyr 13 years ago.
Unit test case to cover the case of transient timeout being set
22807.diff​ (2.1 KB ) - added by kirasong 13 years ago.
Comments, Formatting, Tests in same patch.
22807-test.diff​ (844 bytes ) - added by sandyr 13 years ago.
22807 unit test to handle mu

Download all attachments as: .zip

Change History (14)

#1 @nacin
13 years ago

  • Component General → Options and Meta

#2 @nacin
13 years ago

  • Keywords needs-patch needs-unit-tests added
  • Milestone Awaiting Review → 3.9

Sounds legit. set_transient() properly sets the expiration but get_transient() only looks for an expiration if it is autoloaded.

In set_transient(), we should do a check (when an expiration is supplied) whether the option is already autoloaded. If it is, we should delete it, then let the existing code in set_transient() re-add it.

This needs unit tests.

@shahpranaf
13 years ago

Patch for Updating a non-expiring transient with a new expiry date

#3 @shahpranaf
13 years ago

  • Keywords has-patch dev-feedback added; needs-patch removed

Hello,
I experienced the same problem. So have created patch file and attached.
In set_transient() function, have checked if that transient exists or not. if it exists, I've deleted it and set cache again.

thanks

@sandyr
13 years ago

The correct diff which passes the current unit tests

@sandyr
13 years ago

Unit test case to cover the case of transient timeout being set

@kirasong
13 years ago

Comments, Formatting, Tests in same patch.

#4 @kirasong
13 years ago

  • Keywords commit added; needs-unit-tests removed

Attached 22807.diff​, which is functionally identical, but contains coding standards fixes, additional comments, and contains the tests in the same patch as the changes.

This looks ready, but only if we commit it soon, since I'm hesitant to make changes like this late in the beta cycle.

#5 @nacin
13 years ago

  • Owner set to nacin
  • Resolution → fixed
  • Status new → closed

In 27719:

Transients: Allow a non-expiring transient to be updated with an expiry.

props shahpranaf, sandyr.
fixes #22807.

#6 follow-up: @bpetty
13 years ago

  • Keywords has-patch commit removed
  • Resolution fixed
  • Status closed → reopened

Reopening to address failing tests in multisite. Note that these new tests actually do pass in multisite if you run them isolated from all other tests (--group 22807), however, they don't pass when run with the rest of the tests in the group (--group option). So this is very likely an issue with the tests, not the patch.

$ phpunit -c tests/phpunit/multisite.xml --group option
Installing...
Installing network...
Running as multisite...
Not running ajax tests... To execute these, use --group ajax.
PHPUnit 3.7.28 by Sebastian Bergmann.

Configuration read from /home/bryan/Projects/wp-vagrant/wordpress/tests/phpunit/multisite.xml

.....................FF

Time: 4.82 seconds, Memory: 63.25Mb

There were 2 failures:

1) Tests_Option_Transient::test_transient_data_with_timeout
Failed asserting that '4cdf467f5274a5cb0efec967a5867fc7' is false.

/home/bryan/Projects/wp-vagrant/wordpress/tests/phpunit/tests/option/transient.php:56

2) Tests_Option_Transient::test_transient_add_timeout
Failed asserting that '32bc17ef58dff68148e2645aabc96c57' is false.

/home/bryan/Projects/wp-vagrant/wordpress/tests/phpunit/tests/option/transient.php:77

FAILURES!
Tests: 23, Assertions: 208, Failures: 2.

This could be punted, but there was a fix here applied to 3.9, so I don't want to change the milestone on this ticket, but it needs to be this ticket re-opened to skip these tests for now.

#7 in reply to: ↑ 6 @ocean90
13 years ago

  • Resolution → fixed
  • Status reopened → closed

Replying to bpetty:

Reopening to address failing tests in multisite.

Created #27751.

#8 @bpetty
13 years ago

but it needs to be this ticket re-opened to skip these tests for now

Maybe you could just add #27751 to the failing tests then?

@sandyr
13 years ago

22807 unit test to handle mu

#9 @sandyr
13 years ago

We can ignore the transient test assertion for multisite. Attached the diff for the unit test.

sandeep@localhost:~/wordpress-develop$ phpunit ./tests/phpunit/tests/option/transient.php
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests... To execute these, use --group ajax.
PHPUnit 3.7.31 by Sebastian Bergmann.

Configuration read from /home/sandeep/wordpress-develop/phpunit.xml.dist

....

Time: 7.83 seconds, Memory: 14.00Mb

sandeep@localhost:~/wordpress-develop$ phpunit ./tests/phpunit/tests/option/transient.php -c tests/phpunit/multisite.xml
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests... To execute these, use --group ajax.
PHPUnit 3.7.31 by Sebastian Bergmann.

Configuration read from /home/sandeep/wordpress-develop/phpunit.xml.dist

....

Time: 7.44 seconds, Memory: 14.00Mb

OK (4 tests, 28 assertions)

Note: See TracTickets for help on using tickets.