Actions
Bug #11255
closedCloning host with host group throws error: undefined method `[]' for nil:NilClass
Description
Since #9591, when cloning a host with a host group associated, you get the following error:
| ActionView::Template::Error (undefined method `[]' for nil:NilClass): | 60: <div id="compute_profile" <%= display?(!@host.compute_resource_id) %> > | 61: <%= select_f f, :compute_profile_id, ComputeProfile.visibles, :id, :name, | 62: { :disable_button => _(HostsAndHostgroupsHelper::INHERIT_TEXT), | 63: :disable_button_enabled => @host.hostgroup && @host.hostgroup_id_was.nil? && !params[:host][:compute_profile_id], | 64: :user_set => params[:host] && params[:host][:compute_profile_id] | 65: }, | 66: { :label => _("Compute profile"), :'data-url' => compute_resource_selected_hosts_path, | app/views/hosts/_form.html.erb:63:in `block (2 levels) in _app_views_hosts__form_html_erb___2877621245529704098_63524720' | app/helpers/layout_helper.rb:321:in `form_for' | app/views/hosts/_form.html.erb:8:in `block in _app_views_hosts__form_html_erb___2877621245529704098_63524720' | app/models/taxonomy.rb:66:in `block (2 levels) in as_taxonomy' | app/models/concerns/foreman/thread_session.rb:147:in `as_location' | app/models/taxonomy.rb:65:in `block in as_taxonomy' | app/models/concerns/foreman/thread_session.rb:112:in `as_org' | app/models/taxonomy.rb:64:in `as_taxonomy' | app/views/hosts/_form.html.erb:6:in `_app_views_hosts__form_html_erb___2877621245529704098_63524720' | app/views/hosts/clone.html.erb:3:in `_app_views_hosts_clone_html_erb__3090041382908852687_64038100' | app/controllers/concerns/application_shared.rb:13:in `set_timezone' | app/models/concerns/foreman/thread_session.rb:32:in `clear_thread' | lib/middleware/catch_json_parse_errors.rb:9:in `call'
There are a few accesses to nested parameters that won't have been passed in yet (e.g. params[:host][:compute_profile_id]
) which don't check that params[:host]
is trueish. This only happens when a host group is associated as there's a preceding check for @host.hostgroup
.
Actions