Make WordPress Core

Opened 19 months ago

Closed 19 months ago

Last modified 19 months ago

#57051 closed defect (bug) (fixed)

Fatal error when loading translations early due to a DB error with WPLANG set

Reported by: azurseisme's profile azurseisme Owned by: peterwilsoncc's profile peterwilsoncc
Milestone: 6.1.1 Priority: normal
Severity: normal Version: 6.1
Component: I18N Keywords: has-patch commit fixed-major
Focuses: Cc:

Description (last modified by costdev)

Since a few days (I think after upgrading to WP 6.1) , I have the following bug

PHP Fatal error:  Uncaught Error: Call to undefined function wp_cache_get() in /wp-includes/option.php:165
Stack trace:
#0 /wp-includes/l10n.php(63): get_option()
#1 /wp-includes/l10n.php(139): get_locale()
#2 /wp-includes/l10n.php(766): determine_locale()
#3 /wp-includes/load.php(1395): load_textdomain()
#4 /wp-includes/class-wpdb.php(1198): wp_load_translations_early()
#5 /wp-includes/class-wpdb.php(1858): wpdb->select()
#6 /wp-includes/class-wpdb.php(734): wpdb->db_connect()
#7 /wp-includes/load.php(562): wpdb->__construct()
#8 /wp-settings.php(124): require_wp_db()
#9 /wp-config.php(89): require_once('/home/Web/Azurs...')
#10 /wp-load.php(50): require_once(' in /wp-includes/option.php on line 165, referer: https://subdomain.domain.com/post-name

PHP Fatal error:  Uncaught Error: Call to a member function set() on null in /wp-includes/l10n.php:784
Stack trace:
#0 /wp-includes/l10n.php(872): load_textdomain()
#1 /wp-includes/class-wp-fatal-error-handler.php(47): load_default_textdomain()
#2 [internal function]: WP_Fatal_Error_Handler->handle()\n#3 {main}
thrown in /wp-includes/l10n.php on line 784, referer: https://subdomain.domain.com/post-name

I have applied the patch described by #56952 but no success
The site is down, except for pages in the cache but I cannot access the admin page

Change History (18)

#1 @TimothyBlynJacobs
19 months ago

  • Component changed from Users to I18N
  • Milestone changed from Awaiting Review to 6.1.1
  • Severity changed from major to normal

It looks like wp_load_translations_early now has a side-effect of requiring the Object Cache to be loaded. My first thought is this might be related to some of the translation performance improvements @swissspidy and @ocean90 worked on in #39210.

That being said @azurseisme, the root issue is that it looks like your site is having trouble connecting to your MySQL database which is why WordPress is trying to present this error in the first place. For help with that, I'd recommend reaching out to your hosting company.

#2 @azurseisme
19 months ago

I am self hosting the site, and I have no troubles with the database, no warning messages.
I have restored a database dated 15 october and I have the same issue.
It is very strange since I have a dozen of wordpress sites and the other sites are all OK

Last edited 19 months ago by azurseisme (previous) (diff)

#3 @TimothyBlynJacobs
19 months ago

I don't think it's an issue with the content of your database @azurseisme, but when WordPress tries to select the database you've specified in your wp-config.php file, it is failing to do so.

#4 @costdev
19 months ago

  • Description modified (diff)

#5 @costdev
19 months ago

  • Description modified (diff)

#6 @azurseisme
19 months ago

  • Resolution set to invalid
  • Status changed from new to closed

That was the problem, I am confused.
I close the bug
Thanks a lot

#7 @TimothyBlynJacobs
19 months ago

  • Resolution invalid deleted
  • Status changed from closed to reopened
  • Summary changed from Call to undefined function wp_cache_get() wp-includes/option.php:165 to Fatal error when loading translations early due to a DB error with WPLANG set

I'm glad you got it working @azurseisme!

I'm going to reopen this ticket, though, because WordPress should be showing you a pretty error message instead of fatal erroring in this case.

To replicate, change your DB_NAME to an invalid database, and ensure either WPLANG or $wp_locale_package is defined.

#8 @ocean90
19 months ago

I think the first error will be fixed by #57060. The second one shouldn't be triggered then either but I guess we should still add some sanity check in load_textdomain() whether the $wp_textdomain_registry global is set?

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


19 months ago

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


19 months ago
#10

  • Keywords has-patch added

Ensures that the global $wp_textdomain_registry is set up which is used by the load_*_textdomain() functions.

For testing change your DB_NAME to an invalid database and add define( 'WPLANG', 'de_DE' ); to your wp-config.php.

Errors before:

Fatal error:  Uncaught Error: Call to a member function set() on null in /var/www/src/wp-includes/l10n.php:784
Stack trace:
#0 /var/www/src/wp-includes/load.php(1401): load_textdomain('default', '/var/www/src/wp...', 'de_DE')
#1 /var/www/src/wp-includes/class-wpdb.php(1198): wp_load_translations_early()
#2 /var/www/src/wp-includes/class-wpdb.php(1858): wpdb->select('wordpress_devel...', Object(mysqli))
#3 /var/www/src/wp-includes/class-wpdb.php(734): wpdb->db_connect()
#4 /var/www/src/wp-content/plugins/query-monitor/classes/QM_DB.php(36): wpdb->__construct('root', 'password', 'wordpress_devel...', 'mysql')
#5 /var/www/src/wp-content/plugins/query-monitor/wp-content/db.php(74): QM_DB->__construct('root', 'password', 'wordpress_devel...', 'mysql')
#6 /var/www/src/wp-includes/load.php(550): require_once('/var/www/src/wp...')
#7 /var/www/src/wp-settings.php(124): require_wp_db()
#8 /var/www/wp-config.php(82): require_once('/var/www/src/wp...')
#9 /var/www/src/wp-load.php(55): require_once('/var/www/wp-con...')
#10 /var/www/sr in /var/www/src/wp-includes/l10n.php on line 784

Fatal error:  Uncaught Error: Call to undefined function wp_cache_get() in /var/www/src/wp-includes/option.php:165
Stack trace:
#0 /var/www/src/wp-includes/l10n.php(63): get_option('WPLANG')
#1 /var/www/src/wp-includes/l10n.php(139): get_locale()
#2 /var/www/src/wp-includes/l10n.php(866): determine_locale()
#3 /var/www/src/wp-includes/class-wp-fatal-error-handler.php(47): load_default_textdomain()
#4 [internal function]: WP_Fatal_Error_Handler->handle()
#5 {main}
  thrown in /var/www/src/wp-includes/option.php on line 165

Trac ticket: https://core.trac.wordpress.org/ticket/57051

#11 @ocean90
19 months ago

With [54798] and https://github.com/WordPress/wordpress-develop/pull/3603 this should be fixed. @azurseisme Are you able to test these patches?

@peterwilsoncc commented on PR #3603:


19 months ago
#12

Is it possible to add tests for this?

I suspect not because wp_load_translations_early() is untested but I live in hope.

#13 @peterwilsoncc
19 months ago

  • Keywords commit added

The linked pull request has approvals from three committers, marking as commit ready.

#14 @peterwilsoncc
19 months ago

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

In 54803:

I18N: Initialize textdomain registry in wp_load_translations_early().

Initialize WP_Textdomain_Registry in wp_load_translations_early(). This ensures the global $wp_textdomain_registry is set up prior to loading the translations.

Props azurseisme, TimothyBlynJacobs, costdev, ocean90, flixos90, swissspidy.
Fixes #57051.

#16 @peterwilsoncc
19 months ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for merging to the 6.1 branch.

#17 @desrosj
19 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 54806:

I18N: Initialize textdomain registry in wp_load_translations_early().

Initialize WP_Textdomain_Registry in wp_load_translations_early(). This ensures the global $wp_textdomain_registry is set up prior to loading the translations.

Props azurseisme, TimothyBlynJacobs, costdev, ocean90, flixos90, swissspidy, peterwilsoncc.
Merges [54803] to the 6.1 branch.
Fixes #57051.

#18 @azurseisme
19 months ago

I have tested the patch and now, I have a very useful message in the navigator:
Erreur lors de la connexion à la base de données

very, very useful to understand the error :-)
thanks for your work

Note: See TracTickets for help on using tickets.