Alert user of database table permission errors during search-replace#216
Open
Alert user of database table permission errors during search-replace#216
Conversation
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add alert for database table permissions errors
Alert user of database table permission errors during search-replace
Mar 15, 2026
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
Adds user-facing warnings to wp search-replace when database UPDATE operations fail, so permission/read-only errors don’t result in a misleading “0 replacements” outcome with no explanation.
Changes:
- Emit
WP_CLI::warning()after failed SQL UPDATE queries by checking$wpdb->last_error. - Emit
WP_CLI::warning()after failed per-row$wpdb->update()calls in the PHP replacement path. - Add a Behat scenario that forces an UPDATE failure via a MySQL trigger and asserts a warning is printed.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/Search_Replace_Command.php |
Adds warnings for DB update failures in both SQL and PHP execution paths. |
features/search-replace.feature |
Adds an end-to-end Behat scenario to verify warning output on SQL UPDATE failure. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
776
to
+779
| $wpdb->update( $table, [ $col => $value ], $update_where ); | ||
| if ( $wpdb->last_error ) { | ||
| WP_CLI::warning( sprintf( "Error updating column '%s' in table '%s': %s", $col, $table, $wpdb->last_error ) ); | ||
| } |
| And I run `wp db query "INSERT INTO wp_readonly_test (data) VALUES ('old-value');"` | ||
| And I run `wp db query "CREATE TRIGGER prevent_update BEFORE UPDATE ON wp_readonly_test FOR EACH ROW SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Table is read-only';"` | ||
|
|
||
| When I try `wp search-replace old-value new-value wp_readonly_test --all-tables-with-prefix` |
| Then STDERR should contain: | ||
| """ | ||
| Error updating column 'data' in table 'wp_readonly_test' | ||
| """ |
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.
When a database UPDATE fails (e.g. read-only table, insufficient permissions),
search-replacesilently reported 0 replacements with no indication of why — even after a dry-run showing expected changes.Changes
sql_handle_col): Check$wpdb->last_errorafter$wpdb->query()UPDATE calls; emitWP_CLI::warning()with the table name, column name, and the raw database error.php_handle_col): Same check after each$wpdb->update()call.Example output when a table is not writable:
BEFORE UPDATEtrigger that raises a MySQL signal error, verifying that STDERR contains the expected warning with the column and table name.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.