diff --git a/app/controllers/thesis_controller.rb b/app/controllers/thesis_controller.rb index c1390d61..5ec7ae5e 100644 --- a/app/controllers/thesis_controller.rb +++ b/app/controllers/thesis_controller.rb @@ -119,9 +119,26 @@ def process_thesis def process_thesis_update thesis = Thesis.find(params[:id]) + + # A file may be deleted after the form loads. Drop stale delete rows before update. + drop_stale_deleted_attachment_rows! + removed = deleted_file_list params[:thesis][:files_complete] = false if removed.count.positive? - if thesis.update(thesis_params) + updated = false + retried_for_missing_attachment = false + + begin + updated = thesis.update(thesis_params) + rescue ActiveRecord::RecordNotFound => e + raise unless missing_deleted_attachment_race?(e) && !retried_for_missing_attachment + + retried_for_missing_attachment = true + drop_stale_deleted_attachment_rows! + retry + end + + if updated flash[:success] = "

Your changes to '#{thesis.title}' have been saved.

".html_safe if removed.count.positive? flash[:success] += '

The following files were removed from this thesis. They can still be found attached to their original transfer, via the following links: