Make WordPress Core

Opened 19 months ago

Last modified 19 months ago

#55329 new defect (bug)

add_clean_index function throws PHP notice error

Reported by: gvgvgvijayan's profile gvgvgvijayan Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Upgrade/Install Keywords:
Focuses: administration Cc:

Description

When I tried to add index for newly created column my error log filled with php notice 25 times because of the function drop_index which is called inside the function add_clean_index.

Sample snippet:

<?php
function add_country_iso_code_column() {
        if ( ! function_exists( 'maybe_add_column' ) ) {
                require_once ABSPATH . 'wp-admin/includes/upgrade.php';
        }

        global $wpdb;

        $table_name  = $wpdb->base_prefix . 'defender_lockout_log';
        $column_name = 'country_iso_code';
        $create_ddl  = "ALTER TABLE {$table_name} ADD {$column_name} CHAR(2) DEFAULT NULL";

        maybe_add_column( $table_name, $column_name, $create_ddl );
        add_clean_index( $table_name, $column_name );
}

Error:

[Mon Mar 07 18:45:40.809008 2022] [php:notice] [pid 1167] [client 127.0.0.1:48886] WordPress database error Can't DROP 'country_iso_code_1'; check that column/key exists for query ALTER TABLE `wp_defender_lockout_log` DROP INDEX `country_iso_code_1` made by require_once('wp-admin/network/admin.php'), require_once('wp-admin/admin.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('init'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Defender\\Upgrader->run, WP_Defender\\Upgrader->upgrade_2_8_1, WP_Defender\\Upgrader->add_country_iso_code_column, add_clean_index, drop_index, referer: http://multi.test/wp-admin/network/update.php?action=upload-plugin&package=55&overwrite=update-plugin&_wpnonce=c8b371f5b8

Error log screenshot:
https://i.postimg.cc/2jqsb3Z4/bug-report.png

Change History (1)

This ticket was mentioned in Slack in #core-auto-updates by pbiron. View the logs.


19 months ago

Note: See TracTickets for help on using tickets.