Index: modules/poll/poll.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/poll/poll.module,v
retrieving revision 1.263
diff -u -p -r1.263 poll.module
--- modules/poll/poll.module	15 Jan 2008 07:57:46 -0000	1.263
+++ modules/poll/poll.module	16 Feb 2008 19:51:46 -0000
@@ -339,24 +339,27 @@ function poll_choice_js() {
   // form, Drupal is not aware of this new elements existence and will not
   // process it. We retreive the cached form, add the element, and resave.
   $form = form_get_cache($form_build_id, $form_state);
-  $form['choice_wrapper']['choice'][$delta] = $form_element;
-  form_set_cache($form_build_id, $form, $form_state);
-  $form += array(
-    '#post' => $_POST,
-    '#programmed' => FALSE,
-  );
-
-  // Rebuild the form.
-  $form = form_builder('poll_node_form', $form, $form_state);
-
-  // Render the new output.
-  $choice_form = $form['choice_wrapper']['choice'];
-  unset($choice_form['#prefix'], $choice_form['#suffix']); // Prevent duplicate wrappers.
-  $choice_form[$delta]['#attributes']['class'] = empty($choice_form[$delta]['#attributes']['class']) ? 'ahah-new-content' : $choice_form[$delta]['#attributes']['class'] .' ahah-new-content';
-  $choice_form[$delta]['chvotes']['#value'] = 0;
-  $output = theme('status_messages') . drupal_render($choice_form);
+  if ($form) {
+    $form['choice_wrapper']['choice'][$delta] = $form_element;
+    form_set_cache($form_build_id, $form, $form_state);
+    $form += array(
+      '#post' => $_POST,
+      '#programmed' => FALSE,
+    );
+  
+    // Rebuild the form.
+    $form = form_builder('poll_node_form', $form, $form_state);
+  
+    // Render the new output.
+    $choice_form = $form['choice_wrapper']['choice'];
+    unset($choice_form['#prefix'], $choice_form['#suffix']); // Prevent duplicate wrappers.
+    $choice_form[$delta]['#attributes']['class'] = empty($choice_form[$delta]['#attributes']['class']) ? 'ahah-new-content' : $choice_form[$delta]['#attributes']['class'] .' ahah-new-content';
+    $choice_form[$delta]['chvotes']['#value'] = 0;
+    $output = theme('status_messages') . drupal_render($choice_form);
 
-  drupal_json(array('status' => TRUE, 'data' => $output));
+    drupal_json(array('status' => TRUE, 'data' => $output));
+  }
+  exit;
 }
 
 /**
Index: modules/upload/upload.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/upload/upload.module,v
retrieving revision 1.198
diff -u -p -r1.198 upload.module
--- modules/upload/upload.module	12 Feb 2008 13:49:01 -0000	1.198
+++ modules/upload/upload.module	16 Feb 2008 19:51:46 -0000
@@ -578,58 +578,59 @@ function upload_load($node) {
 function upload_js() {
   // Load the form from the Form API cache.
   $cache = cache_get('form_'. $_POST['form_build_id'], 'cache_form');
-
-  // We only do the upload.module part of the node validation process.
-  $node = (object)$_POST;
-  unset($node->files['upload']);
-  $form = $cache->data;
-  $form_state = array('values' => $_POST);
-
-  // Handle new uploads, and merge tmp files into node-files.
-  upload_node_form_submit($form, $form_state);
-  $node_files = upload_load($node);
-  if (!empty($form_state['values']['files'])) {
-    foreach ($form_state['values']['files'] as $fid => $file) {
-      if (is_numeric($fid)) {
-        $node->files[$fid] = $file;
-        if (!isset($file['filepath'])) {
-          $node->files[$fid] = $node_files[$fid];
+  if ($cache) {
+    // We only do the upload.module part of the node validation process.
+    $node = (object)$_POST;
+    unset($node->files['upload']);
+    $form = $cache->data;
+    $form_state = array('values' => $_POST);
+  
+    // Handle new uploads, and merge tmp files into node-files.
+    upload_node_form_submit($form, $form_state);
+    $node_files = upload_load($node);
+    if (!empty($form_state['values']['files'])) {
+      foreach ($form_state['values']['files'] as $fid => $file) {
+        if (is_numeric($fid)) {
+          $node->files[$fid] = $file;
+          if (!isset($file['filepath'])) {
+            $node->files[$fid] = $node_files[$fid];
+          }
         }
       }
     }
-  }
-  $form = _upload_form($node);
-
-  // Update the default values changed in the $_POST array.
-  $files = isset($_POST['files']) ? $_POST['files'] : array();
-  foreach ($files as $fid => $file) {
-    if (is_numeric($fid)) {
-      $form['files'][$fid]['description']['#default_value'] = $file['description'];
-      $form['files'][$fid]['list']['#default_value'] = isset($file['list']) ? 1 : 0;
-      $form['files'][$fid]['remove']['#default_value'] = isset($file['remove']) ? 1 : 0;
-      $form['files'][$fid]['weight']['#default_value'] = $file['weight'];
+    $form = _upload_form($node);
+  
+    // Update the default values changed in the $_POST array.
+    $files = isset($_POST['files']) ? $_POST['files'] : array();
+    foreach ($files as $fid => $file) {
+      if (is_numeric($fid)) {
+        $form['files'][$fid]['description']['#default_value'] = $file['description'];
+        $form['files'][$fid]['list']['#default_value'] = isset($file['list']) ? 1 : 0;
+        $form['files'][$fid]['remove']['#default_value'] = isset($file['remove']) ? 1 : 0;
+        $form['files'][$fid]['weight']['#default_value'] = $file['weight'];
+      }
     }
+  
+    // Add the new element to the stored form state and resave.
+    $cache->data['attachments']['wrapper'] = array_merge($cache->data['attachments']['wrapper'], $form);
+    cache_set('form_'. $_POST['form_build_id'], $cache->data, 'cache_form', $cache->expire);
+  
+    // Render the form for output.
+    $form += array(
+      '#post' => $_POST,
+      '#programmed' => FALSE,
+      '#tree' => FALSE,
+      '#parents' => array(),
+    );
+    drupal_alter('form', $form, array(), 'upload_js');
+    $form_state = array('submitted' => FALSE);
+    $form = form_builder('upload_js', $form, $form_state);
+    $output = theme('status_messages') . drupal_render($form);
+  
+    // We send the updated file attachments form.
+    // Don't call drupal_json(). ahah.js uses an iframe and
+    // the header output by drupal_json() causes problems in some browsers.
+    print drupal_to_js(array('status' => TRUE, 'data' => $output));
   }
-
-  // Add the new element to the stored form state and resave.
-  $cache->data['attachments']['wrapper'] = array_merge($cache->data['attachments']['wrapper'], $form);
-  cache_set('form_'. $_POST['form_build_id'], $cache->data, 'cache_form', $cache->expire);
-
-  // Render the form for output.
-  $form += array(
-    '#post' => $_POST,
-    '#programmed' => FALSE,
-    '#tree' => FALSE,
-    '#parents' => array(),
-  );
-  drupal_alter('form', $form, array(), 'upload_js');
-  $form_state = array('submitted' => FALSE);
-  $form = form_builder('upload_js', $form, $form_state);
-  $output = theme('status_messages') . drupal_render($form);
-
-  // We send the updated file attachments form.
-  // Don't call drupal_json(). ahah.js uses an iframe and
-  // the header output by drupal_json() causes problems in some browsers.
-  print drupal_to_js(array('status' => TRUE, 'data' => $output));
   exit;
 }
