Can't use file field in custom form - gives AJAX errors I'm building my own form for editing certain fields on a node type, and I'm using field_attach_form() to add the fields from that node type to my form.

Use field_attach_form() to get the fields added to the $form array, and then I hide the ones I don't need by setting them to '#access' => FALSE. For all the textual fields, selects, etc., there's no problem. But when I use a file field (for image uploads), and someone selects a file and clicks 'Upload' on that file field, I get the following two errors:

Notice: Undefined index: field_picture in file_ajax_upload() (line 268 of /path/to/drupal/modules/file/file.module).
Notice: Undefined index: #suffix in file_ajax_upload() (line 277 of /path/to/drupal/modules/file/file.module).


I noticed over on drupal.org, merlinofchaos mentioned that a user could use form_load_include() to include an include that needs to be loaded with the particular form (see: http://drupal.org/node/1161430#comment-4540578), but that was more because that guy additionally had something else he was loading, I think.

The form is built in mymodule.pages.inc, and is called through a menu callback at a path like /admin/config/mymodule/edit-form. What am I missing?
This is a bug in Drupal. The patch in comment #6 works.