Bug 1479293 - find_by hostname produces NoMethodError: undefined method `eq' for nil:NilClass
find_by hostname produces NoMethodError: undefined method `eq' for nil:NilClass
Status: CLOSED NOTABUG
Product: Red Hat CloudForms Management Engine
Classification: Red Hat
Component: Automate (Show other bugs)
5.8.0
Unspecified Unspecified
unspecified Severity medium
: GA
: cfme-future
Assigned To: Greg McCullough
Dave Johnson
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2017-08-08 05:43 EDT by ncatling
Modified: 2017-08-08 12:31 EDT (History)
4 users (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2017-08-08 11:47:09 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description ncatling 2017-08-08 05:43:51 EDT
Description of problem:

find_by hostname produces NoMethodError: undefined method `eq' for nil:NilClass

vmdb
rails c

irb(main):009:0> ExtManagementSystem.find_by(:hostname => "my hostname")
NoMethodError: undefined method `eq' for nil:NilClass
	from /opt/rh/cfme-gemset/gems/activerecord-5.0.3/lib/active_record/relation/predicate_builder/basic_object_handler.rb:9:in `call'
	from /opt/rh/cfme-gemset/gems/activerecord-5.0.3/lib/active_record/relation/predicate_builder.rb:76:in `build'
	from /opt/rh/cfme-gemset/gems/activerecord-5.0.3/lib/active_record/relation/predicate_builder.rb:46:in `expand'
	from /opt/rh/cfme-gemset/gems/activerecord-5.0.3/lib/active_record/relation/predicate_builder.rb:90:in `block in expand_from_hash'
	from /opt/rh/cfme-gemset/gems/activerecord-5.0.3/lib/active_record/relation/predicate_builder.rb:86:in `each'
	from /opt/rh/cfme-gemset/gems/activerecord-5.0.3/lib/active_record/relation/predicate_builder.rb:86:in `flat_map'
	from /opt/rh/cfme-gemset/gems/activerecord-5.0.3/lib/active_record/relation/predicate_builder.rb:86:in `expand_from_hash'
	from /opt/rh/cfme-gemset/gems/activerecord-5.0.3/lib/active_record/relation/predicate_builder.rb:31:in `build_from_hash'
	from /opt/rh/cfme-gemset/gems/activerecord-5.0.3/lib/active_record/relation/where_clause_factory.rb:22:in `build'
	from /opt/rh/cfme-gemset/gems/activerecord-5.0.3/lib/active_record/relation/query_methods.rb:632:in `where!'
	from /opt/rh/cfme-gemset/gems/activerecord-5.0.3/lib/active_record/relation/query_methods.rb:625:in `where'
	from /opt/rh/cfme-gemset/gems/activerecord-5.0.3/lib/active_record/relation/finder_methods.rb:78:in `find_by'
	from /opt/rh/cfme-gemset/gems/activerecord-5.0.3/lib/active_record/querying.rb:7:in `find_by'
	from /opt/rh/cfme-gemset/gems/activerecord-5.0.3/lib/active_record/core.rb:192:in `find_by'
	from (irb):9
	from /opt/rh/cfme-gemset/gems/railties-5.0.3/lib/rails/commands/console.rb:65:in `start'
	from /opt/rh/cfme-gemset/gems/railties-5.0.3/lib/rails/commands/console_helper.rb:9:in `start'
	from /opt/rh/cfme-gemset/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:78:in `console'
	from /opt/rh/cfme-gemset/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
	from /opt/rh/cfme-gemset/gems/railties-5.0.3/lib/rails/commands.rb:18:in `<top (required)>'
	from bin/rails:4:in `require'
	from bin/rails:4:in `<main>'

Version-Release number of selected component (if applicable):
5.8

How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:


Expected results:


Additional info:
Comment 2 Greg McCullough 2017-08-08 11:47:09 EDT
The hostname was moved (delegated) into the Endpoint model:

https://github.com/ManageIQ/manageiq/blob/4a7a549b3cdcadae7a236d7a91489d82cdf5ea8f/app/models/ext_management_system.rb#L110-L121

The query above would need to go against the Endpoint model.

For example:
Endpoint.find_by(:hostname => "my hostname", :resource_type => "ExtManagementSystem")


The query above and in the description are from Rails console queries and not automate, which is the current component type.

The Endpoint query would not work in automate as the service model is not exposed in 5.8.  A work-around would be to loop over all ExtManagementSystem

Example:
provider = $evm.vmdb(:ext_management_system).all.detect {|x| x.hostname == "my hostname"}

Note You need to log in before you can comment on or make changes to this bug.