Make WordPress Core

Opened 10 years ago

Last modified 4 weeks ago

#37685 assigned defect (bug)

Creating new multisite blog - wpmu_create_blog tries to execute queries on non-existent tables

Reported by: fliespl Owned by: realloc
Priority: normal Milestone: Future Release
Component: Networks and Sites Version:
Severity: normal Keywords: has-patch has-unit-tests 2nd-opinion
Cc: Focuses: multisite

Description

I have noticed that while creating new wordpress site in multisite install I get quite a few notices about executed queries while using verbose logging.

query: SELECT option_name, option_value FROM wp_85_options WHERE autoload = 'yes'
status: ERR: Table 'wp1.wp_85_options' doesn't exist

which is triggered by wp_roles()->reinit(); during switch_to_blog function

Another are from get_blogaddress_by_id (inside install_blog function):

query: SELECT option_name, option_value FROM wp_85_options
status: ERR: Table 'wp1.wp_85_options' doesn't exist

query: SELECT option_value FROM wp_85_options WHERE option_name = 'home' LIMIT 1
status: ERR: Table 'wp1.wp_85_options' doesn't exist

query: SELECT option_value FROM wp_85_options WHERE option_name = 'blogname' LIMIT 1
status: ERR: Table 'wp1.wp_85_options' doesn't exist

query: SELECT option_value FROM wp_85_options WHERE option_name = 'siteurl' LIMIT 1
status: ERR: Table 'wp1.wp_85_options' doesn't exist

query: SELECT option_value FROM wp_85_options WHERE option_name = 'post_count' LIMIT 1
status: ERR: Table 'wp1.wp_85_options' doesn't exist

query: SELECT option_name, option_value FROM wp_85_options WHERE autoload = 'yes'
status: ERR: Table 'wp1.wp_85_options' doesn't exist

Wouldn't it make sense to skip execution of those queries unless tables has been created?

  1. get_blogaddress_by_id calls get_blog_details with $get_all as true while it makes no sense since additional fields will either be empty.
  2. Do not call reinit of wp_roles if in blog creation mode

Change History (11)

#1 @johnjamesjacoby
10 years ago

Hey @fliespl. Thanks for the report. Do you have any plugins activated on this installation? If so, are you comfortable listing them here? (I'd like to rule out the chance that a plugin is interfering with the core functionality of the wpmu_create_blog() function.)

#2 @fliespl
10 years ago

@johnjamesjacoby Those are logs from a multisite that was customized at some parts due to size/amount of traffic.

Yet I am pretty confident (99%) that those errors were not triggered by them - I have checked full backtrace that lead to this notices and those were happening (and triggered) solely by core functions (before any plugin / modification hopped in).

Still, I will create later today a clean site without any modifications just to be 100% sure.

#3 @swissspidy
10 years ago

Have you been able to reproduce the problem on a clean site? Are you running WordPress 4.6 or an older version?

#4 @fliespl
10 years ago

I have confirmed it with wordpress 4.6 using such script in mu-plugins

add_filter('shutdown', function() {
    global $EZSQL_ERROR;
    
    file_put_contents(ABSPATH.'/errors.log', print_r($EZSQL_ERROR, true)."\n\n", FILE_APPEND);
});

Errors logged:

    [0] => Array
        (
            [query] => SELECT option_value FROM wp_4_options WHERE option_name = 'wp_4_user_roles' LIMIT 1
            [error_str] => Table 'site.wp_4_options' doesn't exist
        )

    [1] => Array
        (
            [query] => DESCRIBE wp_4_posts
            [error_str] => Table 'site.wp_4_posts' doesn't exist
        )

    [2] => Array
        (
            [query] => SELECT option_value FROM wp_4_options WHERE option_name = 'blogname' LIMIT 1
            [error_str] => Table 'site.wp_4_options' doesn't exist
        )

    [3] => Array
        (
            [query] => SELECT option_value FROM wp_4_options WHERE option_name = 'siteurl' LIMIT 1
            [error_str] => Table 'site.wp_4_options' doesn't exist
        )

    [4] => Array
        (
            [query] => SELECT option_value FROM wp_4_options WHERE option_name = 'post_count' LIMIT 1
            [error_str] => Table 'site.wp_4_options' doesn't exist
        )

    [5] => Array
        (
            [query] => SELECT option_value FROM wp_4_options WHERE option_name = 'home' LIMIT 1
            [error_str] => Table 'site.wp_4_options' doesn't exist
        )

This ticket was mentioned in Slack in #core-multisite by flixos90. View the logs.


10 years ago

#6 @flixos90
10 years ago

  • Keywords reporter-feedback added

@fliespl Was your above test with a clean install without any plugins?

#7 @fliespl
10 years ago

@flixos90 correct. No themes/plugins installed. Just unpacked wordpress and created multisite.

#8 @realloc
4 weeks ago

Most of this was resolved in 5.1, when site creation moved from install_blog() to wp_initialize_site(). install_blog() is deprecated; get_blogaddress_by_id() now builds the URL from get_site() instead of the new site's options, and the DESCRIBE check moved into wp_is_site_initialized(), which unhooks wp_switch_roles_and_user before switching and wraps the query in suppress_errors().

One query remains. wp_initialize_site() calls switch_to_blog() before make_db_current_silent() without that guard, so WP_Roles::for_site() ends up calling get_option( 'wp_N_user_roles' ) against a table that does not exist yet.

#9 @realloc
4 weeks ago

  • Keywords reporter-feedback removed
  • MilestoneFuture Release

This ticket was mentioned in PR #12860 on WordPress/wordpress-develop by @realloc.


4 weeks ago
#10

  • Keywords has-patch has-unit-tests added

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

wp_initialize_site() switched to the new site before its tables existed, letting the switch_blog hook query a nonexistent options table; this suppresses that query and reorders the roles setup so populate_roles() still targets the correct site.

#11 @realloc
4 weeks ago

  • Keywords 2nd-opinion added
  • Owner set to realloc
  • Status newassigned
Note: See TracTickets for help on using tickets.