#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 |
---|---|---|---|
Milestone: | 3.9 | Priority: | normal |
Severity: | normal | Version: | 3.4.2 |
Component: | Options, Meta APIs | Keywords: | dev-feedback |
Focuses: | Cc: |
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)
Change History (14)
#2
@
11 years ago
- Keywords needs-patch needs-unit-tests added
- Milestone changed from Awaiting Review to 3.9
#3
@
11 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
#4
@
11 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
@
11 years ago
- Owner set to nacin
- Resolution set to fixed
- Status changed from new to closed
In 27719:
#6
follow-up:
↓ 7
@
11 years ago
- Keywords has-patch commit removed
- Resolution fixed deleted
- Status changed from closed to 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.
#8
@
11 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?
#9
@
11 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)
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.