Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The problem is quite simple.
If for some reason, a developper forget to add a "return $schema" or return a null value at the end of an hook_schema implementation, the cache 'schema' entry will be left empty at the next rebuild (update.php or when you clean the cache table). As this cache entry is used for every modules, this means that there is no schema available at all anymore (node, etc.) and result is an unusable site.
Drupal core should add a test for this :
--- drupal-6.4/includes/common.inc 2008-08-13 19:59:12.000000000 -0400
+++ drupal/includes/common.inc 2008-09-08 05:54:04.000000000 -0400
@@ -3058,8 +3058,10 @@
// Invoke hook_schema for all modules.
foreach (module_implements('schema') as $module) {
$current = module_invoke($module, 'schema');
- _drupal_initialize_schema($module, $current);
- $schema = array_merge($schema, $current);
+ if (!empty($current)) {
+ _drupal_initialize_schema($module, $current);
+ $schema = array_merge($schema, $current);
+ }
}
Comments
Comment #1
mikejoconnor CreditAttribution: mikejoconnor commentedI ran in to this same issue today, and came up with nearly the same solution. I used is_array(), however that method is slower than empty(). This patch does solve the problem as long as the user doesn't return something other than an array.
Comment #2
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis needs to be discussed and go in 7.x first.
Comment #3
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis is in fact a duplicate of #287647: Invalid hook_schema() result can trash entire schema.