Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#55632 closed defect (bug) (fixed)

WordPress database error when running PHPUnit tests

Reported by: chouby's profile Chouby Owned by: peterwilsoncc's profile peterwilsoncc
Milestone: 6.0 Priority: normal
Severity: normal Version: 6.0
Component: Upgrade/Install Keywords: needs-testing has-patch
Focuses: Cc:

Description

When running PHPUnit tests, a database error is reported before the first test is run

WordPress database error Table 'wordpress_develop_tests.wptests_posts' doesn't exist for query 
					SELECT   wptests_posts.ID
					FROM wptests_posts 
					WHERE 1=1  AND ( 
  0 = 1
) AND wptests_posts.post_type = 'wp_global_styles' AND ((wptests_posts.post_status = 'publish'))
					GROUP BY wptests_posts.ID
					ORDER BY wptests_posts.post_date DESC
<div id="error"><p class="wpdberror"><strong>WordPress database error:</strong> [Table &#039;wordpress_develop_tests.wptests_posts&#039; doesn&#039;t exist]<br /><code>
					SELECT   wptests_posts.ID
					FROM wptests_posts 
					LIMIT 0, 1
					WHERE 1=1  AND ( 
				 made by require_once('wp-settings.php'), do_action('wp_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, {closure}, {closure}, WP_Theme_JSON_Resolver::get_merged_data, WP_Theme_JSON_Resolver::get_user_data, WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles, wp_get_recent_posts, get_posts, WP_Query->query, WP_Query->get_posts
  0 = 1
) AND wptests_posts.post_type = &#039;wp_global_styles&#039; AND ((wptests_posts.post_status = &#039;publish&#039;))
					GROUP BY wptests_posts.ID
					ORDER BY wptests_posts.post_date DESC
					LIMIT 0, 1
				</code></p></div>

See for example: https://github.com/WordPress/wordpress-develop/runs/6195555843?check_suite_focus=true

Attachments (1)

55632.diff (543 bytes) - added by peterwilsoncc 2 years ago.

Download all attachments as: .zip

Change History (11)

#2 @SergeyBiryukov
2 years ago

  • Milestone changed from Awaiting Review to 6.0

#3 @costdev
2 years ago

  • Component changed from General to Build/Test Tools
  • Keywords needs-patch needs-testing added

Hi @Chouby, I'll check this out when I'm back at my PC later today.

#4 @peterwilsoncc
2 years ago

cc @hellofromTonya

Thanks for reporting this @Chouby, as always your efforts testing beta and RC releases is greatly appreciated.

@peterwilsoncc
2 years ago

#5 follow-up: @peterwilsoncc
2 years ago

  • Keywords has-patch added; needs-patch removed

I was able to reproduce this locally.

  1. Open test database in your favourite MySQL interface
  2. Drop all of the tables
  3. Run phpunit and observe the error described above.

55632.diff fixes the problem by assuming there are no webfonts to enqueue during installation and bypassing the check of WP_Theme_JSON_Resolver. An alternative might be to move $fn_register_webfonts to run early on the wp_enqueue_scripts hook.

The fuller solution is probably at a lower level in which FSE themes check whether WP is installed before attempting to access the FSE posts.

This ticket was mentioned in PR #2638 on WordPress/wordpress-develop by peterwilsoncc.


2 years ago
#6

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

Just making sure the tests pass.

#7 in reply to: ↑ 5 ; follow-up: @SergeyBiryukov
2 years ago

Replying to peterwilsoncc:

An alternative might be to move $fn_register_webfonts to run early on the wp_enqueue_scripts hook.

Just noting that this option also works in my testing. Could that be the preferred approach here? Is there a use case for registering webfonts earlier, like currently on the wp_loaded hook?

#8 in reply to: ↑ 7 @peterwilsoncc
2 years ago

  • Component changed from Build/Test Tools to Upgrade/Install

I realised overnight the same error would occur during installation. As it's a user facing component, I've moved the ticket to that.

Replying to SergeyBiryukov:

Just noting that this option also works in my testing.

Thanks for the logic check, I've updated the linked pull request to use wp_enqueue_scripts, 9. Technically the priority isn't needed as the actions run in order of registration but I figured I'd make it clear what was happening.

Is there a use case for registering webfonts earlier, like currently on the wp_loaded hook?

Not that I am aware of for theme.json.

Testing notes

In all cases, you will need to check out the branch of the linked pull request. This can be done by running npm run grunt patch:https://github.com/WordPress/wordpress-develop/pull/2638 in a wordpress-develop environment.

Unit tests

  1. Drop test database tables in test database
  2. Run phpunit
  3. Check for reported database table does not exist errors

WP CLI Installation

In your local environments root directory:

  1. Run wp db reset
  2. Run wp core install --title=WP-DEV --admin_user=admin --admin_password=password --admin_email=admin@example.com --url=wp-dev.local (replace the URL as appropriate)
  3. Check for reported database table does not exist errors

Manual Installation

  1. In your local environments root directory run wp db reset. Alternatively drop all tables via a MySQL interface
  2. Visit your local environment in the browser and follow the installation steps
  3. Check for reported database table does not exist errors

#9 @peterwilsoncc
2 years ago

  • Owner set to peterwilsoncc
  • Resolution set to fixed
  • Status changed from new to closed

In 53306:

Install: Prevent DB errors caused by web fonts API.

Bypass checking theme.json for web fonts during the installation of WordPress.

During installation the active theme is considered to be Twenty Twenty-Two (the default theme). As a block theme this prompts a database call when the web fonts API checks the theme.json settings, this triggers a database error during installation as the database tables do not exist.

Props chouby, costdev, peterwilsoncc, sergeybiryukov.
Fixes #55632.

Note: See TracTickets for help on using tickets.