Repository navigation
Read settings back correctly after they're first written or deleted - #101
Merged
Merged
Conversation
The settings cache could return stale values within the request that changed a setting: - A setting written for the first time read back as unset. addUpdateSetting() looks up the row's ID with getSetting( 'onlyID' ), and on a miss getSetting() cached the default even for that ID lookup. The insert that followed didn't clear it. ID lookups no longer cache. - A deleted setting kept reading back its old value: deleteSetting() didn't invalidate the cache the way addUpdateSetting() does. It now does. Updating an existing setting was not affected. Tests: first write, read-while-absent then write, delete, and update all read back correctly in the same request. The first three fail on the previous code. Full suite 188 green. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two stale-cache bugs in the DAL's settings cache (the "issue 3504" mitigation cache), both within a single request:
addUpdateSetting()looks up the row ID withgetSetting( array( 'key' => …, 'onlyID' => true ) )to decide between insert and update. On a miss,getSetting()cached the default (false), even for an ID lookup, and the insert that followed didn't clear it. So any code that creates a setting and reads it back in the same request gotfalse.deleteSetting()didn't invalidate the cache the wayaddUpdateSetting()does.Updating an existing setting was not affected. That's why this mostly shows up on fresh installs and in tests.
Fix
getSetting(): don't cache a miss whenonlyIDis set.deleteSetting(): reset the cache, asaddUpdateSetting()does.Testing
tests/php/dal/Setting_Readback_Test.php: first write, read while absent then write, delete, and update. The first three fail on trunk and pass here.OK (188 tests, 602 assertions). phpcs-changed clean.Related
This is very likely the cause of #100's phpunit failure in CI. CI starts from a fresh database, so the custom-field definitions that test registers are a first-time write and read back empty. Locally the settings row already existed from earlier runs. I'll re-run #100's CI once this is in.
🤖 Generated with Claude Code