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'