Drupal crashes after clearing caches and after enabling new module

Created on 22 February 2022, almost 3 years ago
Updated 27 September 2023, about 1 year ago

Problem/Motivation

After update to Drupal 7.87 to 7.88, Drupal crashes after clearing cashes at:

/admin/config/development/performance" and clicking "Clear all caches"

and crashes after enabling a newly installed module at:

/admin/modules and clicking "Save configuration"

The following message is displayed: Error: The website encountered an unexpected error. Please try again later.

Steps to reproduce

1. Update from Drupal 7.87 to 7.88

2. Go to /admin/config/development/performance and click "Clear all caches" or go to /admin/modules and check mark to enable on a module and click "Save configuration"

3. The following errors display:

Notice: Trying to access array offset on value of type bool in /home/mysite/www/www/mytestingsite/includes/common.inc on line 7340
Warning: Invalid argument supplied for foreach() in /home/mysite/www/www/mytestingsite/includes/common.inc on line 7340
Notice: Trying to access array offset on value of type bool in /home/mysite/www/www/mytestingsite//includes/common.inc on line 7360
Warning: array_keys() expects parameter 1 to be array, null given in /home/mysite/www/www/mytestingsite/includes/common.inc on line 7360

4. All pages then display only: "Error: The website encountered an unexpected error. Please try again later."

5. If I type in a URL for a page that doesn't exist (ex: http://mysite/fake-page) forcing the Drupal to take me to "Page Not Found" the error goes away and the site appears normal again. Also, Drupal had gone ahead and enabled the module or cleared the caches.

6. Lines 7340 and 7360 refer to this section in common.inc

/**
 * Retrieves the type for every field in a table schema.
 *
 * @param $table
 *   The name of the table from which to retrieve type information.
 *
 * @return
 *   An array of types, keyed by field name.
 */
function drupal_schema_field_types($table) {
  $table_schema = drupal_get_schema($table);
  $field_types = array();
  foreach ($table_schema['fields'] as $field_name => $field_info) {
    $field_types[$field_name] = isset($field_info['type']) ? $field_info['type'] : NULL;
  }
  return $field_types;
}

/**
 * Retrieves a list of fields from a table schema.
 *
 * The returned list is suitable for use in an SQL query.
 *
 * @param $table
 *   The name of the table from which to retrieve fields.
 * @param
 *   An optional prefix to to all fields.
 *
 * @return An array of fields.
 */
function drupal_schema_fields_sql($table, $prefix = NULL) {
  $schema = drupal_get_schema($table);
  $fields = array_keys($schema['fields']);
  if ($prefix) {
    $columns = array();
    foreach ($fields as $field) {
      $columns[] = "$prefix.$field";
    }
    return $columns;
  }
  else {
    return $fields;
  }
}

Proposed resolution

I am not a developer and don't understand the root cause of this error. Be kind, please.

🐛 Bug report
Status

Needs review

Version

7.0 ⚰️

Component
Other 

Last updated 1 day ago

Created by

🇺🇸United States lkwetterauer

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India Neeraj420

    I am also facing the same issue even after upgrading to 7.97. Whenever I clear the cache views stop giving results.
    I have to always run update.php and every this back to normal. I am not sure why or what is the problem.

  • First commit to issue fork.
  • Open on Drupal.org →
    Environment: PHP 8.2 & MySQL 8
    57:45
    57:45
    Queueing
  • @pavel_spn opened merge request.
  • Hi there!

    As the drupal_get_schema() function (see bootstrap.inc) can returns FALSE I propose to add additional checks
    to prevent FATAL errors on PHP8.1

    for drupal_schema_field_types():
    `$table_schema_fields = (!empty($table_schema['fields']) && is_array($table_schema['fields'])) ? $table_schema['fields'] : array();`

    for drupal_schema_fields_sql():
    `$schema_fields = (!empty($schema['fields']) && is_array($schema['fields'])) ? $schema['fields'] : array();`

    All changes see in proposed merge request.

    Best Regards,
    Pavel

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    2,161 pass
  • Status changed to Needs review over 1 year ago
  • 🇵🇱Poland driverok

    checked MR!4835 - fixed the problem for me.

    STR - any Drupal 7 site with incorrectly ( not fully ) deleted fields (instances). Basically, everything that makes drupal_get_schema() return False.

    Thanks @Pavel_SPN!

  • 🇰🇿Kazakhstan Dmitrii_Zadorozhnyi

    It works for me! The problem appeared after incorrectly removed fields

  • 🇧🇾Belarus O-khainouski

    Checked MR!4835 - fixed the problem for me.
    Thanks @Pavel_SPN!

  • 🇸🇰Slovakia poker10

    @Dmitrii_Zadorozhnyi can you please explain a bit more, how this could happen (or what exactly do you meant by this)?

    incorrectly removed fields
    

    Thanks!

  • 🇰🇿Kazakhstan Dmitrii_Zadorozhnyi

    @poker10
    As far as I remember after uninstalling module, which implemented some fields, fields were not completely removed from the database. So after switching to PHP 8.1 the error occurred. Module was removed a long time ago, so I can't provide more details

Production build 0.71.5 2024