Project

General

Profile

Actions

Bug #18809

closed

Fix searching hosts based on compliance_policy

Added by Marek Hulán over 7 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Difficulty:
Triaged:
No
Fixed in Releases:
Found in Releases:

Description

Some change in AREL has broken searching by compliance_policy. I tried to make it work without ext_method which does not work because of missing `id` in SQL (probably because of non-standard relations we use). I ended up with queries using pluck instead. Also I removed the != operator which probably never worked correctly.

Actions #1

Updated by The Foreman Bot over 7 years ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman_openscap/pull/244 added
Actions #2

Updated by Marek Hulán over 7 years ago

Reproducing steps:

1) go to hosts page
2) use search term like "compliance_policy = something"
3) you'll get 500 with trace like below

Expected result:

You should only see host assigned to compliance policy with name something

The trace:

2017-03-06T18:03:41 0575f63c [app] [F] 
 | ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR:  syntax error at or near "ON" 
 | LINE 1: ... "foreman_openscap_assets"."assetable_type" = $3, ON "forema...
 |                                                              ^
 | : SELECT  "hosts".* FROM "hosts" WHERE "hosts"."type" IN ('Host::Managed') AND (("hosts"."id" IN (0, "hosts", NULL, "hosts"."id", NULL, 0, "hosts", 0, "foreman_openscap_assets", 0, "foreman_openscap_assets", 0, "foreman_openscap_assets"."assetable_id", 0, "hosts", 0, "hosts"."id", "foreman_openscap_assets"."assetable_id" = "hosts"."id", 0, "foreman_openscap_assets", 0, "foreman_openscap_assets"."assetable_type", $1, "foreman_openscap_assets"."assetable_type" = $2, "foreman_openscap_assets"."assetable_id" = "hosts"."id" AND "foreman_openscap_assets"."assetable_type" = $3, ON "foreman_openscap_assets"."assetable_id" = "hosts"."id" AND "foreman_openscap_assets"."assetable_type" = $4, INNER JOIN "foreman_openscap_assets" ON "foreman_openscap_assets"."assetable_id" = "hosts"."id" AND "foreman_openscap_assets"."assetable_type" = $5, 0, "foreman_openscap_asset_policies", 0, "foreman_openscap_asset_policies", 0, "foreman_openscap_asset_policies"."asset_id", 0, "foreman_openscap_assets", 0, "foreman_openscap_assets"."id", "foreman_openscap_asset_policies"."asset_id" = "foreman_openscap_assets"."id", ON "foreman_openscap_asset_policies"."asset_id" = "foreman_openscap_assets"."id", INNER JOIN "foreman_openscap_asset_policies" ON "foreman_openscap_asset_policies"."asset_id" = "foreman_openscap_assets"."id", 0, "foreman_openscap_policies", 0, "foreman_openscap_policies", 0, "foreman_openscap_policies"."id", 0, "foreman_openscap_asset_policies", 0, "foreman_openscap_asset_policies"."policy_id", "foreman_openscap_policies"."id" = "foreman_openscap_asset_policies"."policy_id", ON "foreman_openscap_policies"."id" = "foreman_openscap_asset_policies"."policy_id", INNER JOIN "foreman_openscap_policies" ON "foreman_openscap_policies"."id" = "foreman_openscap_asset_policies"."policy_id", NULL, "hosts" INNER JOIN "foreman_openscap_assets" ON "foreman_openscap_assets"."assetable_id" = "hosts"."id" AND "foreman_openscap_assets"."assetable_type" = $6 INNER JOIN "foreman_openscap_asset_policies" ON "foreman_openscap_asset_policies"."asset_id" = "foreman_openscap_assets"."id" INNER JOIN "foreman_openscap_policies" ON "foreman_openscap_policies"."id" = "foreman_openscap_asset_policies"."policy_id", 0, "hosts", 0, "hosts"."type", 'Host::Managed', NULL, "hosts"."type" IN ('Host::Managed'), foreman_openscap_policies.name = 'normal', (foreman_openscap_policies.name = 'normal'), "hosts"."type" IN ('Host::Managed') AND (foreman_openscap_policies.name = 'normal'), NULL, NULL, NULL, NULL, SELECT "hosts"."id" FROM "hosts" INNER JOIN "foreman_openscap_assets" ON "foreman_openscap_assets"."assetable_id" = "hosts"."id" AND "foreman_openscap_assets"."assetable_type" = $7 INNER JOIN "foreman_openscap_asset_policies" ON "foreman_openscap_asset_policies"."asset_id" = "foreman_openscap_assets"."id" INNER JOIN "foreman_openscap_policies" ON "foreman_openscap_policies"."id" = "foreman_openscap_asset_policies"."policy_id" WHERE "hosts"."type" IN ('Host::Managed') AND (foreman_openscap_policies.name = 'normal'), NULL, NULL, NULL, NULL, NULL, SELECT "hosts"."id" FROM "hosts" INNER JOIN "foreman_openscap_assets" ON "foreman_openscap_assets"."assetable_id" = "hosts"."id" AND "foreman_openscap_assets"."assetable_type" = $8 INNER JOIN "foreman_openscap_asset_policies" ON "foreman_openscap_asset_policies"."asset_id" = "foreman_openscap_assets"."id" INNER JOIN "foreman_openscap_policies" ON "foreman_openscap_policies"."id" = "foreman_openscap_asset_policies"."policy_id" WHERE "hosts"."type" IN ('Host::Managed') AND (foreman_openscap_policies.name = 'normal'))))  ORDER BY "hosts"."name" ASC LIMIT 20 OFFSET 0):
 |   app/controllers/hosts_controller.rb:55:in `block (2 levels) in index'
 |   app/controllers/hosts_controller.rb:51:in `index'
 |   app/controllers/concerns/application_shared.rb:14:in `set_timezone'
 |   app/models/concerns/foreman/thread_session.rb:32:in `clear_thread'
 |   lib/middleware/catch_json_parse_errors.rb:8:in `call'
 |   lib/middleware/tagged_logging.rb:18:in `call'

Actions #3

Updated by Marek Hulán over 7 years ago

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

Also available in: Atom PDF