Project:Drupal core
Version:7.x-dev
Component:base system
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed (duplicate)

Issue Summary

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

#1

Version:6.4» 6.x-dev
Status:needs review» reviewed & tested by the community

I 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.

#2

Version:6.x-dev» 7.x-dev
Status:reviewed & tested by the community» needs review

This needs to be discussed and go in 7.x first.

#3

Status:needs review» closed (duplicate)

This is in fact a duplicate of #287647: Invalid hook_schema() result can trash entire schema.

nobody click here