Repository navigation
Options, Meta APIs: Avoid caching options as nonexistent after database errors. - #12595
gunjanjaswal wants to merge 2 commits into
Conversation
…se errors. A failed `SELECT` in `get_option()` and `get_network_option()` returns null, which is indistinguishable from a missing row. Both functions treated that as proof of non-existence and primed the `notoptions` cache, hiding an option that is still in the database until the cache is invalidated. `delete_option()` had the same problem from the other direction: it primed `notoptions` before checking the result of `$wpdb->delete()`, so a failed delete marked a still-present option as nonexistent. The `notoptions` writes are now gated on the query being known to have succeeded. `delete_network_option()` is adjusted to match: it was guarded on a truthy result, so a successful delete affecting zero rows never primed the cache. Zero rows is a successful query, so it still primes; only false does not.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
Motivation from the field: Trac #61762 just picked up a report of this hitting a multisite in production. The initial DB error poisoned This PR fixes that at the root: gating the |
|
Gentle bump — this has been open a couple of months without a review. It's a focused fix so the options and metadata caches don't persist a "nonexistent" marker after a transient database error, which otherwise masks the real value until the cache is cleared. Happy to rebase or adjust anything if that makes it easier to pick up. |
|
Circling back on this one. Happy to rebase it to refresh CI whenever that's useful — the lone red check is a stale July matrix job showing core's own PHP 8.2 deprecation warnings, not anything from this change. The fix itself is unchanged and focused: don't cache an option as "nonexistent" when the read actually failed on a database error, which otherwise sticks a false negative in the cache until it's flushed. There's since been a field report on Trac #61762 of this biting a multisite, so a first review whenever someone has a window would be much appreciated. |
Adds regression tests on top of the existing coverage for the notoptions fix. Each one simulates the next request of a persistent object cache by flushing the cache and restoring only the persisted `notoptions` entry, so a false "missing" marker written after a failed query would hide an option that still exists. Also checks that a failed network option read on one network does not touch another network's `{network_id}:notoptions` entry in the `site-options` group.
Follow-up to the work on #61762.
See https://core.trac.wordpress.org/ticket/61762.
|
Added a round of regression tests from @AceMedia (props AceMedia), merged in from gunjanjaswal#1. They cover the angle the existing tests didn't: the next request. The current tests check that No production code changed — tests only, built on this PR's head. Ran the full option suite locally (PHP 8.3, MySQL 8.0): |
|
A nudge on this one — it's been open a while without a review. It avoids caching a stale value in the options/meta APIs for the case described in the ticket. The single failing cell is the known PHP 8.0 / MariaDB multisite flake, not related to this patch. Happy to take another pass if anything's needed. |
Trac ticket: https://core.trac.wordpress.org/ticket/61762
$wpdb->get_row()returns null both when an option row is missing and when the query itself failed.get_option()andget_network_option()treated the second case as the first and primed thenotoptionscache, so a transient database error could hide an option that is still in the database. With a persistent object cache that state sticks around, and the option keeps returning its default long after the database has recovered.delete_option()had the same problem from the other direction: it primednotoptionsbefore checking the result of$wpdb->delete(), so a failed delete marked a still-present option as nonexistent.Each
notoptionswrite is now gated on the query being known to have succeeded, using$wpdb->last_erroron the read paths andfalse !== $resulton the delete paths.delete_network_option()was guarded on a truthy result, which meant a successful delete affecting zero rows never primed the cache. Zero rows is a successful query, so it primes there now too.Adds regression tests covering the read and delete paths, including the zero-row case.
Clearing
notoptionsinadd_network_option()andupdate_network_option()is left for a follow-up, per the ticket.