Project

General

Profile

Bug #15050

ISE on scoped search for Hosts

Added by John Mitsch about 7 years ago. Updated almost 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Search
Target version:
Difficulty:
Triaged:
Bugzilla link:
Fixed in Releases:
Found in Releases:
Red Hat JIRA:

Description

Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1335044
Description of problem:
There is a nasty traceback while searching for an existing hostname in Content Hosts using scoped search.

search query: "my-host-1.domain.org"
production.log:
2016-05-11 04:30:59 [app] [I] Processing by Api::V2::HostsController#index as JSON
2016-05-11 04:30:59 [app] [I] Parameters: {"organization_id"=>"1", "page"=>"1", "search"=>"my-host-1.lab.eng.brq.redhat.com", "sort_by"=>"name", "sort_order"=>"ASC", "apiv"=>"v2"}
2016-05-11 04:30:59 [app] [W] Action failed | PG::Error: ERROR: missing FROM-clause entry for table "organizations_hosts" | LINE 1: ...14_r9, "taxonomies"."katello_default" AS t14_r10, "organizat...

searching for non-existing hostname works fine.

Version-Release number of selected component (if applicable):
6.2.0 Beta GA10.1

How reproducible:
always

Steps to Reproduce:
1. register a host to your satellite so it appears in Content Hosts
2. Try to put its hostname to the search field and hit search
3. check production.log

Actual results:
ISE

Expected results:
Search query is being validated performed on all applicable fields.

Additional info:
Workaround is to use the explicit-field search query:
name = my-host-1.domain.org or
name ~ my-host-1.domain.org

- I'm requesting a blocker flag for this BZ as this will be hit quite often by users (single word search queries are the most commonly used)

Associated revisions

Revision b9a3e39d (diff)
Added by John Mitsch about 7 years ago

Fixes #15050 - Scoped search hostname w/o field no longer ISEs

Searching for an existing host's name without any fields
specified results in an SQL error:
missing FROM-clause entry for
table \"organizations_hosts\"

This can be reproduced using
curl -X GET -u admin 'http://localhost:3000/api/v2/
hosts?organization_id=2&search=<hostname>'

where <hostname> is an existing hostname

setting this field to explicit_only will fix the issue

My perspective of what the larger issue is:
This has to do with scoped search using AR's includes1
which generates a sql query with a non-existing table,
organization_hosts

This is shown on the command line

Host.includes([:location, :organization])
.where("taxonomies.name" => "org1")
.to_sql.include?("organizations_hosts")
evaluates to true

I am not sure about what to do for a more permanent fix,
it looks like its the same issue as
https://github.com/theforeman/foreman/commit/
5185335248abd0104ec0b791df5e641eeae9da6b

Revision 26678da1 (diff)
Added by John Mitsch almost 7 years ago

Fixes #15050 - Scoped search hostname w/o field no longer ISEs

Searching for an existing host's name without any fields
specified results in an SQL error:
missing FROM-clause entry for
table \"organizations_hosts\"

This can be reproduced using
curl -X GET -u admin 'http://localhost:3000/api/v2/
hosts?organization_id=2&search=<hostname>'

where <hostname> is an existing hostname

setting this field to explicit_only will fix the issue

My perspective of what the larger issue is:
This has to do with scoped search using AR's includes1
which generates a sql query with a non-existing table,
organization_hosts

This is shown on the command line

Host.includes([:location, :organization])
.where("taxonomies.name" => "org1")
.to_sql.include?("organizations_hosts")
evaluates to true

I am not sure about what to do for a more permanent fix,
it looks like its the same issue as
https://github.com/theforeman/foreman/commit/
5185335248abd0104ec0b791df5e641eeae9da6b

(cherry picked from commit b9a3e39d0a62b1eda43b6ce8da54b636c1500e58)

History

#1 Updated by John Mitsch about 7 years ago

To reproduce in foreman use:

curl -X GET -u admin 'http://localhost:3000/api/v2/hosts?organization_id=2&search=&lt;hostname&gt;'

where <hostname> is an actual host's name.

This seems to be an error in scoped search. If you comment this line out

https://github.com/theforeman/foreman/blob/f4459c1/app/models/concerns/hostext/search.rb#L70

or add :only_explicit => true

that query works.

It seems to be a bug in scoped search that has already caused issues in foreman -

https://github.com/theforeman/foreman/commit/5185335248abd0104ec0b791df5e641eeae9da6b

#2 Updated by Dominic Cleal about 7 years ago

  • Category changed from Inventory to Search

I'm guessing you've a further search added by a plugin or Katello that adds in joins to taxonomies, and these are conflicting? This doesn't seem to happen on develop.

#3 Updated by John Mitsch about 7 years ago

  • Subject changed from ISE on scoped search for Content Hosts to ISE on scoped search for Hosts

I've tested and was able to recreate this on just a foreman (no katello or plugins) development environment.

Did you test that curl command using a host that had been already created? It only errors when you search for an actual host.

i.e. curl -X GET -u admin 'http://localhost:3000/api/v2/hosts?organization_id=2&search=myhost.example.com'

#4 Updated by The Foreman Bot about 7 years ago

  • Status changed from New to Ready For Testing
  • Assignee set to John Mitsch
  • Pull request https://github.com/theforeman/foreman/pull/3535 added

#5 Updated by John Mitsch about 7 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#6 Updated by Dominic Cleal about 7 years ago

  • Legacy Backlogs Release (now unused) set to 159

Also available in: Atom PDF