Index: modules/block/block.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.module,v
retrieving revision 1.424
diff -u -p -r1.424 block.module
--- modules/block/block.module	17 Jun 2010 13:16:57 -0000	1.424
+++ modules/block/block.module	20 Jun 2010 18:49:58 -0000
@@ -847,12 +847,14 @@ function _block_get_cache_id($block) {
  * Implements hook_flush_caches().
  */
 function block_flush_caches() {
-  // Rehash blocks for active themes. We don't use list_themes() here,
-  // because if MAINTENANCE_MODE is defined it skips reading the database,
-  // and we can't tell which themes are active.
-  $themes = db_query("SELECT name FROM {system} WHERE type = 'theme' AND status = 1");
-  foreach ($themes as $theme) {
-    _block_rehash($theme->name);
+  // Rehash blocks for active themes after running database updates. We don't
+  // use list_themes() here, because if MAINTENANCE_MODE is defined it skips
+  // reading the database, and we can't tell which themes are active.
+  if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update') {
+    $themes = db_query("SELECT name FROM {system} WHERE type = 'theme' AND status = 1");
+    foreach ($themes as $theme) {
+      _block_rehash($theme->name);
+    }
   }
 
   return array('cache_block');
Index: modules/block/block.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.test,v
retrieving revision 1.53
diff -u -p -r1.53 block.test
--- modules/block/block.test	15 Jun 2010 16:19:28 -0000	1.53
+++ modules/block/block.test	20 Jun 2010 18:49:58 -0000
@@ -278,8 +278,7 @@ class BlockTestCase extends DrupalWebTes
 
     // Disable caching for this block.
     variable_set('block_test_caching', DRUPAL_NO_CACHE);
-    // Flushing all caches should call _block_rehash().
-    drupal_flush_all_caches();
+    $this->drupalGet('admin/structure/block');
     // Verify that the database is updated with the new caching mode.
     $current_caching = db_query("SELECT cache FROM {block} WHERE module = 'block_test' AND delta = 'test_cache'")->fetchField();
     $this->assertEqual($current_caching, DRUPAL_NO_CACHE, t("Test block's database entry updated to DRUPAL_NO_CACHE."));
