When a managed file form element is added to a form with multiple files allowed, once files have been added, it will display a remove selected button. The issue is that this remove button is also a submit button and the javascript triggers all elements with the .js-form-submit class. This means then when you upload another file, it triggers both the upload button and the remove button, resulting in two temporary file entities being created with the same URI. When you hit save, only one of these is marked as permanent, meaning that once the cron job runs, it deletes the temporary file, which results in the permanent filename being deleted from the system.

The code needs updating to target specifically the upload button. I'm just about to submit a patch.

CommentFileSizeAuthor
#2 2884052.patch1.28 KBcharlotte.b
Members fund testing for the Drupal project. Drupal Association Learn more

Comments

charlotte.b created an issue. See original summary.

charlotte.b’s picture

charlotte.b’s picture

Status: Active » Needs review
cilefen’s picture

cilefen’s picture

We define the loss of stored data as critical. There are a handful of issues related to file deletion that I've related to this issue.

swentel’s picture

Does it really need to be a custom form ? It would explain a couple of issues in the queue already with sudden (sometimes random) deletion of files, very nice find!

swentel’s picture

Issue tags: +JavaScript

Tagging so javascript maintainers will see this.

charlotte.b’s picture

It looks as though the bug won't occur on entity fields as the file widget displays the files in a table above the managed file form element, so it shouldn't trigger any of the remove buttons.

droplet’s picture

Wim Leers’s picture

Related issues:

Can the reporters of this issue also look into #2869855: Race condition in hook_file_validate causes data loss, which I suspect focused on the wrong thing to point to as the root cause? I think the root cause of that issue (and their steps to reproduce) is the same as the root cause reported here.

charlotte.b’s picture

It's definitely a related issue. I've managed to replicate it by hitting save on a custom entity type before the ajax upload call has completed. As this only happens due to the AJAX call, is it worth disabling form submit buttons using JavaScript until we receive a response?

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.