Skip to content

Read settings back correctly after they're first written or deleted - #101

Merged
tellyworth merged 1 commit into
trunkfrom
fix/setting-first-write-readback
Nov 10, 2026
Merged

tellyworth merged 1 commit into
trunkfrom
fix/setting-first-write-readback

Conversation

@tellyworth

Copy link
Copy Markdown
Contributor

What

Two stale-cache bugs in the DAL's settings cache (the "issue 3504" mitigation cache), both within a single request:

  1. A setting written for the first time read back as unset. addUpdateSetting() looks up the row ID with getSetting( 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 got false.
  2. A deleted setting kept reading back its old value. deleteSetting() didn't invalidate the cache the way addUpdateSetting() 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 when onlyID is set.
  • deleteSetting(): reset the cache, as addUpdateSetting() does.

Testing

  • New 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.
  • Full suite: 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

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>
@tellyworth
tellyworth merged commit 8563cd1 into trunk Nov 10, 2026
4 checks passed
@tellyworth tellyworth added this to the 6.8.6 milestone Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant