=== modified file 'includes/form.inc'
--- includes/form.inc	2009-04-11 22:19:44 +0000
+++ includes/form.inc	2009-04-16 02:32:21 +0000
@@ -208,7 +208,7 @@ function drupal_build_form($form_id, &$f
   // the form, passing in the latest $form_state in addition to any
   // other variables passed into drupal_get_form().
 
-  if (!empty($form_state['rebuild']) || !empty($form_state['storage'])) {
+  if (!form_get_errors() && (!empty($form_state['rebuild']) || !empty($form_state['storage']))) {
     $form = drupal_rebuild_form($form_id, $form_state);
   }
 

=== modified file 'modules/node/node.test'
--- modules/node/node.test	2009-04-15 13:28:08 +0000
+++ modules/node/node.test	2009-04-16 02:37:00 +0000
@@ -631,7 +631,7 @@ class NodePostSettingsTestCase extends D
 
 /**
  * Ensure that data added to nodes by other modules appears in RSS feeds.
- * 
+ *
  * Create a node, enable the node_test module to ensure that extra data is
  * added to the node->content array, then verify that the data appears on the
  * sitewide RSS feed at rss.xml.
@@ -664,3 +664,49 @@ class NodeRSSContentTestCase extends Dru
     $this->assertText($test_text, t('Extra node content appears in RSS feed.'));
   }
 }
+
+/**
+ * Create a two step node and ensure the taxonomy selection sticks.
+ *
+ * Create a vocabulary for two step nodes, add a term. Create a two step node,
+ * select the term, preview the node in the second step, which will make the
+ * validation fail and check the taxonomy selection still sticks.
+ */
+class TwoStepNodeTestCase extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => t('Two step node'),
+      'description' => t('Test that two step nodes keep their taxonomy.'),
+      'group' => t('Node')
+    );
+  }
+
+  function setUp() {
+    parent::setUp('taxonomy', 'twostepnode');
+  }
+
+  /**
+   * Create a two step node and ensure the taxonomy selection sticks.
+   */
+  function testTwoStepNode() {
+    $this->account = $this->drupalCreateUser(array('create twostepnode content'));
+    $this->drupalLogin($this->account);
+    // Create a vocabulary.
+    $vocabulary = new stdClass();
+    $vocabulary->name = $this->randomName();
+    $vocabulary->nodes = array('twostepnode' => 'twostepnode');
+    taxonomy_vocabulary_save($vocabulary);
+    $term = new stdClass();
+    $term->name = $this->randomName();
+    $term->vid = $vocabulary->vid;
+    taxonomy_term_save($term);
+    $title = $this->randomName();
+    $edit = array('title' => $title);
+    $this->drupalPost('node/add/twostepnode', $edit, t('Next'));
+    $edit = array("taxonomy[$term->vid]" => $term->tid);
+    $this->drupalPost(NULL, $edit, t('Preview'));
+    $this->assertText(t('Required body field is required.'), t('Error present'));
+    $options = $this->xpath('//option[@value="'. $term->tid .'"]');
+    $this->assertTrue($options[0]['selected'] == 'selected', t('Term still selected'));
+  }
+}

