locale.module breaks page if cache was emptied

suit4 - May 9, 2008 - 10:20
Project:Drupal
Version:5.7
Component:locale.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:patch (code needs review)
Description

I migrated a page from my development system to the live site, and therefore cleared the cache pages.

A bug in locale.module stops the page from working.

If the cache was cleared, there is no data in there, the there will be no $cache->data to unserialize.
If using http://drupal.org/project/backup_migrate, the cache tables are excluded from the db export by default, so the error occurs here, too.

Bug location: Line 185

<?php
     
if (!$cache) {
       
locale_refresh_cache();
       
$cache = cache_get("locale:$locale", 'cache');
      }
         
$locale_t = unserialize($cache->data); // The bug occurs here
...
?>

should read:

<?php
     
if (!$cache) {
       
locale_refresh_cache();
       
$cache = cache_get("locale:$locale", 'cache');
      }
      if(
$cache){
         
$locale_t = unserialize($cache->data);
      }
?>

I created a simple patch.

AttachmentSize
locale_dont_unserialize_nonexisting_cache.patch431 bytes
 
 

Drupal is a registered trademark of Dries Buytaert.