Bug #24478
closedUnable to delete subnet NoMethodError: undefined method `klass' for nil:NilClass
Description
Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1541002
Description of problem: Trying to delete subnet which is used by provisioned host gives error
2018-02-01 08:40:36 c64b0466 [app] [W] Action failed | NoMethodError: undefined method `klass' for nil:NilClass | Did you mean? class | /opt/theforeman/tfm/root/usr/share/gems/gems/scoped_search-4.1.2/lib/scoped_search/query_builder.rb:31:in `class_for' | /opt/theforeman/tfm/root/usr/share/gems/gems/scoped_search-4.1.2/lib/scoped_search/query_builder.rb:18:in `build_query' | /usr/share/foreman/app/services/authorizer.rb:96:in `build_filtered_scope_components' | /usr/share/foreman/app/services/authorizer.rb:55:in `find_collection' | /usr/share/foreman/app/models/concerns/authorizable.rb:27:in `authorized_as' | /usr/share/foreman/app/models/concerns/authorizable.rb:65:in `authorized' | /usr/share/foreman/app/services/association_authorizer.rb:10:in `authorized_associations' | /usr/share/foreman/lib/core_extensions.rb:45:in `block (2 levels) in before_destroy' | /opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/relation/delegation.rb:46:in `each' | /opt/rh/rh-ror42/root/usr/share/gems/gems/activerecord-4.2.6/lib/active_record/relation/delegation.rb:46:in `each' | /usr/share/foreman/lib/core_extensions.rb:42:in `block in before_destroy' | /usr/share/foreman/lib/core_extensions.rb:41:in `each'
Version-Release number of selected component (if applicable): Satellite 6.3 snap 34
How reproducible: always
Steps to Reproduce:
1. Create subnet
2. Provision a host using created subnet
3. Try to delete subnet
Actual results:
Error as Oops, we're sorry but something went wrong undefined method `klass' for nil:NilClass Did you mean? class
and production.log showed 500 internal server error (see attachment).
Expected results: It should show warning as "subnet is used by host"
Additional info: It is regression. Working correctly in 6.2.14.