file_field_widget_form error when programatically creating nodes
Looks like this is actually a problem in Drupal itself. In modules/file/file.field.inc the function field_form_get_state has a line like this near the bottom (just before the return statement):

$elements['#file_upload_description'] = theme('file_upload_help', array('description' =&gt; '', 'upload_validators' =&gt; $elements[0]['#upload_validators']));


The issue is a small if condition a few lines back which looks like this:

if (($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $delta &lt; $field['cardinality']) &amp;&amp; empty($form_state['programmed'])) {
    $elements[$delta] = $element;
    ...
    some more stuff
}


Since I am submitting the form programmatically with drupal_form_submit(), it adds in $form_state['programmed']; thus, the control statement's condition fails, and $elements[0] does not exist.