Problem:
Trying to get a fact value via API results in a backtrace in foreman logs. I’m guessing it has something to do with taxonomy, but I get this even with an administrator user.
If I enable sql debugging and run the sql query from the logs, it returns the correct value. But I still get an Action failed
in the log with a backtrace.
Expected outcome:
Fact values should be returned
Foreman and Proxy versions:
3.4.0
Distribution and version:
RHEL8
Other relevant data:
Exception from Foreman log:
2022-09-26T10:38:22 [I|app|0781bb01] Parameters: {"search"=>"name ~ testfact and host = lxserv1638", "per_page"=>"999999", "apiv"=>"v2", "fact_value"=>{}}
...
2022-09-26T10:33:52 [I|app|eb49e08b] Backtrace for 'Action failed' error (ActiveModel::MissingAttributeError): missing attribute: fact_name_id
eb49e08b | /usr/share/gems/gems/activemodel-6.1.6.1/lib/active_model/attribute.rb:222:in `value'
eb49e08b | /usr/share/gems/gems/activemodel-6.1.6.1/lib/active_model/attribute_set/builder.rb:55:in `block in fetch_value'
eb49e08b | /usr/share/gems/gems/activemodel-6.1.6.1/lib/active_model/attribute_set/builder.rb:46:in `fetch'
eb49e08b | /usr/share/gems/gems/activemodel-6.1.6.1/lib/active_model/attribute_set/builder.rb:46:in `fetch_value'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/attribute_methods/read.rb:36:in `_read_attribute'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/associations/belongs_to_association.rb:132:in `stale_state'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/associations/association.rb:79:in `loaded!'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/associations/association.rb:96:in `target='
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/associations/join_dependency.rb:284:in `construct_model'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/associations/join_dependency.rb:264:in `block in construct'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/associations/join_dependency.rb:241:in `each'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/associations/join_dependency.rb:241:in `construct'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/associations/join_dependency.rb:142:in `block (2 levels) in instantiate'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/result.rb:62:in `block in each'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/result.rb:62:in `each'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/result.rb:62:in `each'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/associations/join_dependency.rb:139:in `block in instantiate'
eb49e08b | /usr/share/gems/gems/activesupport-6.1.6.1/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/associations/join_dependency.rb:138:in `instantiate'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/relation.rb:839:in `block (2 levels) in exec_queries'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/relation/finder_methods.rb:421:in `apply_join_dependency'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/relation.rb:833:in `block in exec_queries'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/relation.rb:861:in `skip_query_cache_if_necessary'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/relation.rb:828:in `exec_queries'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/relation.rb:631:in `load'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/relation.rb:249:in `records'
eb49e08b | /usr/share/gems/gems/activerecord-6.1.6.1/lib/active_record/relation/delegation.rb:88:in `each'
eb49e08b | /usr/share/foreman/app/controllers/api/v2/fact_values_controller.rb:32:in `build_facts_hash'
...
The following sql query is logged and when I run i manually it works (newlines inserted for readability):
2022-09-26T10:38:22 [D|sql|0781bb01] SQL (8.0ms)
SELECT "fact_values"."value", fact_names.name as factname, hosts.name as hostname,
"fact_values"."id" AS t0_r0, "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
FROM "fact_values"
INNER JOIN "hosts" ON "hosts"."organization_id" = $1 AND "hosts"."location_id" = $2
AND "hosts"."id" = "fact_values"."host_id"
INNER JOIN "fact_names" ON "fact_names"."id" = "fact_values"."fact_name_id"
WHERE "fact_values"."host_id" IN (SELECT "hosts"."id" FROM "hosts"
WHERE "hosts"."type" = $3 AND "hosts"."organization_id" = $4 AND "hosts"."location_id" = $5
AND "hosts"."organization_id" = $6 AND "hosts"."location_id" = $7) AND (fact_names.name <> '_timestamp')
AND ((("fact_names"."name" ILIKE '%testfact%') AND (hosts.name = 'lxserv1638')))
ORDER BY "fact_values"."value" ASC NULLS FIRST LIMIT $8 OFFSET $9
[["organization_id", 1], ["location_id", 3], ["type", "Host::Managed"], ["organization_id", 1], ["location_id", 3], ["organization_id", 1], ["location_id", 3], ["LIMIT", 999999], ["OFFSET", 0]]
2022-09-26T10:38:22 [W|app|0781bb01] Action failed