Bug #22631

When user with role filters view_facts and view_hosts attempts to view hosts based on local, custom fact, it fails with SQL error

Added by Daniel Lobato Garcia over 3 years ago.

Target version:
Bugzilla link:
Pull request:
Fixed in Releases:
Found in Releases:


Cloned from

Description of problem:

I have a user setup to only view a subset of hosts and facts using a custom fact filter. The hosts works fine, when I goto montior -> facts in the UI it errors out with the following message:

Oops, we're sorry but something went wrong PG::Error: ERROR: missing FROM-clause entry for table "fact_names_1" LINE 1: ...LD')) AND ( <> '_timestamp') AND ((fact_names... ^ : SELECT "fact_values"."id" AS t0_r0, "fact_values"."value" AS t0_r1, "fact_values"."fact_name_id" AS t0_r2, "fact_values"."host_id" AS t0_r3, "fact_values"."updated_at" AS t0_r4, "fact_values"."created_at" AS t0_r5, "fact_names"."id" AS t1_r0, "fact_names"."name" AS t1_r1, "fact_names"."updated_at" AS t1_r2, "fact_names"."created_at" AS t1_r3, "fact_names"."compose" AS t1_r4, "fact_names"."short_name" AS t1_r5, "fact_names"."type" AS t1_r6, "fact_names"."ancestry" AS t1_r7, "hosts"."id" AS t2_r0, "hosts"."name" AS t2_r1, "hosts"."last_compile" AS t2_r2, "hosts"."last_report" AS t2_r3, "hosts"."updated_at" AS t2_r4, "hosts"."created_at" AS t2_r5, "hosts"."root_pass" AS t2_r6, "hosts"."architecture_id" AS t2_r7, "hosts"."operatingsystem_id" AS t2_r8, "hosts"."environment_id" AS t2_r9, "hosts"."ptable_id" AS t2_r10, "hosts"."medium_id" AS t2_r11, "hosts"."build" AS t2_r12, "hosts"."comment" AS t2_r13, "hosts"."disk" AS t2_r14, "hosts"."installed_at" AS t2_r15, "hosts"."model_id" AS t2_r16, "hosts"."hostgroup_id" AS t2_r17, "hosts"."owner_id" AS t2_r18, "hosts"."owner_type" AS t2_r19, "hosts"."enabled" AS t2_r20, "hosts"."puppet_ca_proxy_id" AS t2_r21, "hosts"."managed" AS t2_r22, "hosts"."use_image" AS t2_r23, "hosts"."image_file" AS t2_r24, "hosts"."uuid" AS t2_r25, "hosts"."compute_resource_id" AS t2_r26, "hosts"."puppet_proxy_id" AS t2_r27, "hosts"."certname" AS t2_r28, "hosts"."image_id" AS t2_r29, "hosts"."organization_id" AS t2_r30, "hosts"."location_id" AS t2_r31, "hosts"."type" AS t2_r32, "hosts"."otp" AS t2_r33, "hosts"."realm_id" AS t2_r34, "hosts"."compute_profile_id" AS t2_r35, "hosts"."provision_method" AS t2_r36, "hosts"."content_source_id" AS t2_r37, "hosts"."grub_pass" AS t2_r38, "hosts"."content_view_id" AS t2_r39, "hosts"."lifecycle_environment_id" AS t2_r40, "hosts"."global_status" AS t2_r41, "hosts"."lookup_value_matcher" AS t2_r42, "hosts"."discovery_rule_id" AS t2_r43, "hosts"."openscap_proxy_id" AS t2_r44 FROM "fact_values" INNER JOIN "hosts" ON "hosts"."id" = "fact_values"."host_id" AND "hosts"."type" IN ('Host::Managed') AND "hosts"."organization_id" IN (1) AND "hosts"."location_id" IN (3, 4, 2) LEFT OUTER JOIN "fact_names" ON "fact_names"."id" = "fact_values"."fact_name_id" WHERE (( = 'status' AND fact_values.value = 'BUILD')) AND ( <> '_timestamp') AND (( = 'status' AND fact_values_1.value = 'BUILD')) AND "hosts"."organization_id" IN (1) AND "hosts"."location_id" IN (3, 4, 2) AND "fact_names"."ancestry" IS NULL ORDER BY "fact_values"."value" ASC NULLS FIRST LIMIT 20 OFFSET 0

Steps to Reproduce:
1. Create a local custom fact for the host, such as status: BUILD
2. Create a role with the following filters (see attachment "filters")

Fact value view_facts fact.status = BUILD
Host view_hosts fact.status = BUILD

3. Attempt to view a host list filtered by this fact.

Also available in: Atom PDF