Actions
Bug #25367
closedReport templates clone doesn't create clone but only renames the report
Description
While trying to clone the report template via API call it gets only renamed and new record is not added.
[ INFO 2018-11-01T16:24:40 API] POST /api/report_templates/142/clone [DEBUG 2018-11-01T16:24:40 API] Params: { "report_template" => { "name" => "Cloned report" }, "name" => "Cloned report" } [DEBUG 2018-11-01T16:24:40 API] Headers: {} [DEBUG 2018-11-01T16:24:40 API] Using authenticator: HammerCLIForeman::Api::InteractiveBasicAuth [DEBUG 2018-11-01T16:24:44 API] Response: { "id" => 142, "name" => "Cloned report", "template" => "<%#\nname: Registered hosts\nsnippet: false\nmodel: ReportTemplate\nrequire:\n - plugin: katello\n version: 3.9.0\n-%>\n<%- load_hosts(search: '', includes: [:operatingsystem,:subscriptions,:fact_values,:fact_names,:applicable_errata,:applicable_rpms]).each_record do |host| -%>\n<%- report_row(\n 'Name': host.name,\n 'Ip': host.ip,\n 'Operating System': host.operatingsystem,\n 'Subscriptions': host_subscriptions(host),\n 'Applicable Errata': host_applicable_errata_ids(host),\n 'Owner': host.owner,\n 'Kernel': host.facts['kernelrelease'],\n 'Latest kernel available': host_latest_applicable_rpm_version(host, 'kernel')\n ) -%>\n<%- end -%>\n<%= report_render -%>", "snippet" => false, "template_kind_id" => nil, "created_at" => "2018-10-09T08:13:05.901Z", "updated_at" => "2018-11-01T15:24:43.904Z", "locked" => false, "default" => false, "vendor" => nil, "os_family" => nil, "job_category" => "Miscellaneous", "provider_type" => nil, "description_format" => nil, "execution_timeout_interval" => nil }
It is caused by using the `clone` method in the controller. Since Rails 4 it seems to behave differently and the `dup` should be used instead.
Some more details can be found in e.g. https://medium.com/@raycent/ruby-clone-vs-dup-8a49b295f29a
Actions