Enable upload.module.

Go and create a Page content. Open "File attachments" fieldset and select a file.
Hit "Attach": the file will be correctly uploaded (you can see it in the files/ directory) and correctly showed in-place in "File attachments" section.
Now hit "Save". No file is listed as attachment for the new node. Even if you go to edit the node, no attachment is shown.

Now follow the same workflow, but instead of saving directly hit "Preview", wait preview to load and then "Save". The file will be correctly attached.

Same behaviour has been recorded with download method set to public or private.
Also still same behaviour if you don't hit "Attach" after selecting the file.

Comments

flevour’s picture

In #drupal chx suggests mentioning #160039 won't fix the issue.

flevour’s picture

Link to bug #160039.

flevour’s picture

I have found a weird behaviour. I activated the devel module and set it to show redirects.
I also modified upload_save in upload.module to dpr($node) when it's called.

I then proceed as I noted in the report:
- go to create a page
- select an attachment and do not press "Attach"
- press Save

The page informing about the redirect shows the dpr($node) with an empty $node->files.
I then refresh. To my surprise dpr($node) shows $node->files with correct file informations.

Maybe it's something magic involved with FAPI or something like that.

flevour’s picture

Commenting form_set_cache call in drupal_get_form() temporarily fixes the issue. This means attaching a file and saving directly now works. I am discussing this issue chx to tackle in IRC right now.
As per chx suggestion, I am working with HEAD + patch #160039.

flevour’s picture

I found out the problem is about caching. Setting $form['#cache'] = FALSE; infact fixes the problem.
As eaton, pwolanin and frando tell me, use of #cache is considered a bug in core, so I am not even bothering to submit a patch.
Just in case you need a quick fix, add "$form['#cache'] = FALSE;" at line 220 in upload.module

flevour’s picture

Title: Failure to attach a file on direct save of a node (preview+save works) » *_node_form cache loading prevents files to be attached to node on direct save/update

Chaning title to a more descriptive one.
Preview+save/update still works.

chx’s picture

Status: Active » Closed (duplicate)

Despite this issue is senior I patched http://drupal.org/node/168813 so I close this one.