Skip to content

Upgrade/Install: Fail gracefully when database upgrade queries fail. - #16184

Open
ClearanceClarence wants to merge 1 commit into
WordPress:trunkfrom
ClearanceClarence:36887-db-upgrade-fail-gracefully
Open

ClearanceClarence wants to merge 1 commit into
WordPress:trunkfrom
ClearanceClarence:36887-db-upgrade-fail-gracefully

Conversation

@ClearanceClarence

@ClearanceClarence ClearanceClarence commented Nov 23, 2026 •

Copy link
Copy Markdown

Database upgrades currently report "Update Complete" and bump db_version even when upgrade queries fail. This makes wp_upgrade() and wp-admin/upgrade.php detect failed queries and fail gracefully.

Changes

  • wp_upgrade() now returns true on success (or when no upgrade is needed) and a WP_Error listing the failed queries otherwise. On failure the wp_upgrade action does not fire.
  • upgrade_all() no longer updates db_version / db_upgraded if a query failed, so the upgrade runs again once the cause is resolved (see General: Check the function set_time_limit() exist before calling #4027).
  • wp-admin/upgrade.php shows a "Database Update Failed" screen with the number of failed queries, a pointer to the server error log and a "Try Again" button. Queries are not printed, since this screen is reachable without authentication. The step=upgrade_db endpoint responds with HTTP 500 on failure.
  • wp-admin/network/upgrade.php stops with a message when a site's upgrade request does not return 200.
  • wpdb::print_error() records whether errors were suppressed in each $EZSQL_ERROR entry. Suppressed errors are treated as expected failures and do not fail the upgrade.
  • The hide_errors() / show_errors() blocks around expected failures in older upgrade routines and drop_index() now use suppress_errors().

Design notes

  • All upgrade steps still run, and failures are reported at the end, rather than halting on the first failed query. Halting part-way would leave the schema in a less predictable state.
  • A query that fails on every run keeps the site on the failure screen, because db_version is never bumped. Feedback welcome on whether a filter to ignore specific errors is wanted.
  • drop_index() no longer force-enables error display after running.

Testing instructions

  1. Drop an index that dbDelta() will restore: ALTER TABLE wp_posts DROP INDEX post_name;
  2. Restrict the database user to SELECT, INSERT, UPDATE, DELETE.
  3. Lower db_version in wp_options by one.
  4. Visit /wp-admin/upgrade.php and run the update. Expected: "Database Update Failed", db_version unchanged, the denied ALTER TABLE in the error log.
  5. Restore the user's privileges and click "Try Again". Expected: "Update Complete", db_version updated, index restored.

Screenshots

1-update-required 2-update-failed 3-update-complete

Trac ticket

https://core.trac.wordpress.org/ticket/36887

Use of AI Tools

AI assistance: Yes
Tool(s): Claude
Model(s): Claude Fable 5.2
Used for: Documentation of the code


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

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:

Props cccode.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@ClearanceClarence

Copy link
Copy Markdown
Author

@propsbot refresh

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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