I have a WP "unit" test, run in multisite mode, that looks like this:
class EffectsTest extends WP_UnitTestCase {
public function test_wp_insert_site() {
$id = wp_insert_site([
'title' => 'My Site Title',
'domain' => 'foo.multicare.org',
'meta' => [
'whatever' => 'whatever',
],
]);
$this->assertNotEmpty($id);
}
}
The test passes but it's triggering the error:
WordPress database error Can't reopen table: 'a' for query DELETE a, b FROM wptests_2_options a, wptests_2_options b
WHERE a.option_name LIKE '\\_transient\\_%'
AND a.option_name NOT LIKE '\\_transient\\_timeout\\_%'
AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )
AND b.option_value < 1605216174
made by PHPUnit\TextUI\Command::main, PHPUnit\TextUI\Command->run, PHPUnit\TextUI\TestRunner->doRun,
PHPUnit\Framework\TestSuite->run, PHPUnit\Framework\TestSuite->run, PHPUnit\Framework\TestSuite->run,
PHPUnit\Framework\TestCase->run, PHPUnit\Framework\TestResult->run, PHPUnit\Framework\TestCase->runBare,
PHPUnit\Framework\TestCase->runTest, MultiCare\Integration\EffectsTest->test_wp_insert_site,
wp_insert_site, do_action('wp_initialize_site'), WP_Hook->do_action, WP_Hook->apply_filters,
wp_initialize_site, populate_options, delete_expired_transients
The actual error originates in delete_expired_transients()
, which appears to be deleting from two aliases to the same table, $wpdb->options
:
"DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b..."
MySQL doesn't seem to like that. So my question is, is there a way to prevent this without patching WP Core? Seems like a core bug to me, but perhaps I'm missing something.
(The actual test calls a function from my application code, so I'm not just testing wp_insert_site()
. But that's irrelevant here because it's the call to wp_insert_site()
that's triggering the error.)
mc_central_data_id
andmc_central_data_site
update_post_meta()
is never advantageous and is always less secure, so you should just never rely on array meta fields, is that right?