noosfero | WIP: Custom forms graphs (!1597)

Rodrigo Souto gitlab at mg.gitlab.com
Mon Aug 20 17:50:07 BRT 2018


Rodrigo Souto started a new discussion on plugins/custom_forms/lib/custom_forms_plugin/csv_handler.rb:

>          end
>          alternative.id
>        end
> -      CustomFormsPlugin::Answer.new(field: field, value: ids.join(','),
> -                                    imported: true)
> +      answer = CustomFormsPlugin::Answer.new(field: field, value: nil, imported: true)
> +
> +      ids.each do |id|
> +        form_answer = CustomFormsPlugin::FormAnswer.create(answer_id: answer.id, alternative_id: id)

There are 2 problems here:
1.  You are using `create` without exclamation mark and not treating the case where it may fail. You should at least use `create!` to ensure that if some form_answer fails we get to know. Since this is being used already inside a begin/rescue on the method `import_csv` adding the exclamation mark should be enough.
2. The answer is build above here but only saved after it's returned on the line `csv << submission_row(submission, fields)` on the method `generate_csv`. What if the answer has something invalid and can't be created? Then you'd already have created form_answers for an answer that wasn't even created. So you should also use `create!` for the answer creation above as well to ensure it's created before the form_answers.

-- 
Reply to this email directly or view it on GitLab: https://gitlab.com/noosfero/noosfero/merge_requests/1597#note_95697965
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20180820/415b61b7/attachment-0001.html>


More information about the Noosfero-dev mailing list