Hello
I retrieved an error from foreman’s log when it happens:
2025-09-26T17:29:47 [I|app|c808cf10] Backtrace for ‘Action failed’ error (ActiveRecord::AssociationTypeMismatch): Host::Managed(#17980) expected, got #<Host::Base id: 15526, name: “myhostname”, last_compile: nil, last_report: nil, updated_at: “2025-09-26 15:29:42.524364000 +0000”, created_at: “2025-09-26 15:29:42.524364000 +0000”, root_pass: nil, architecture_id: 1, operatingsystem_
id: 3, ptable_id: nil, medium_id: nil, build: false, comment: “”, disk: nil, installed_at: nil, model_id: nil, hostgroup_id: 4, owner_id: 5, owner_type: “User”, enabled: true, puppet_ca_proxy_id: nil, m
anaged: false, use_image: nil, image_file: nil, uuid: nil, compute_resource_id: nil, puppet_proxy_id: nil, certname: nil, image_id: nil, organization_id: 1, location_id: 25, type: nil, otp: nil, realm_i
d: nil, compute_profile_id: nil, provision_method: nil, grub_pass: nil, global_status: 0, lookup_value_matcher: [FILTERED], pxe_loader: nil, initiated_at: nil, build_errors: nil, creator_id: 5> which is
an instance of Host::Base(#17900)
c808cf10 | /usr/share/gems/gems/activerecord-6.1.7.10/lib/active_record/associations/association.rb:283:in raise_on_type_mismatch!' c808cf10 | /usr/share/gems/gems/activerecord-6.1.7.10/lib/active_record/associations/belongs_to_association.rb:77:in replace’
c808cf10 | /usr/share/gems/gems/activerecord-6.1.7.10/lib/active_record/associations/singular_association.rb:17:in writer' c808cf10 | /usr/share/gems/gems/activerecord-6.1.7.10/lib/active_record/associations/builder/association.rb:111:in host=’
c808cf10 | /usr/share/gems/gems/activemodel-6.1.7.10/lib/active_model/attribute_assignment.rb:49:in public_send' c808cf10 | /usr/share/gems/gems/activemodel-6.1.7.10/lib/active_model/attribute_assignment.rb:49:in _assign_attribute’
c808cf10 | /usr/share/gems/gems/activerecord-6.1.7.10/lib/active_record/attribute_assignment.rb:21:in block in _assign_attributes' c808cf10 | /usr/share/gems/gems/activerecord-6.1.7.10/lib/active_record/attribute_assignment.rb:13:in each’
c808cf10 | /usr/share/gems/gems/activerecord-6.1.7.10/lib/active_record/attribute_assignment.rb:13:in _assign_attributes' c808cf10 | /usr/share/gems/gems/activemodel-6.1.7.10/lib/active_model/attribute_assignment.rb:34:in assign_attributes’
c808cf10 | /usr/share/gems/gems/activerecord-6.1.7.10/lib/active_record/core.rb:525:in initialize' c808cf10 | /usr/share/gems/gems/activerecord-6.1.7.10/lib/active_record/inheritance.rb:72:in new’
c808cf10 | /usr/share/gems/gems/activerecord-6.1.7.10/lib/active_record/inheritance.rb:72:in new' c808cf10 | /usr/share/foreman/app/models/concerns/foreman/sti.rb:13:in new’
c808cf10 | /usr/share/foreman/app/services/report_importer.rb:159:in create_report_and_logs' c808cf10 | /usr/share/foreman/app/services/config_report_importer.rb:21:in create_report_and_logs’
c808cf10 | /usr/share/foreman/app/services/report_importer.rb:42:in block in import' c808cf10 | /usr/share/foreman/lib/foreman/telemetry_helper.rb:28:in telemetry_duration_histogram’
c808cf10 | /usr/share/foreman/app/services/report_importer.rb:41:in import' c808cf10 | /usr/share/foreman/app/services/report_importer.rb:23:in import’
c808cf10 | /usr/share/foreman/app/models/config_report.rb:28:in import' c808cf10 | /usr/share/foreman/app/controllers/api/v2/config_reports_controller.rb:43:in create’
c808cf10 | /usr/share/gems/gems/actionpack-6.1.7.10/lib/action_controller/metal/basic_implicit_render.rb:6:in send_action' c808cf10 | /usr/share/gems/gems/actionpack-6.1.7.10/lib/abstract_controller/base.rb:228:in process_action’
c808cf10 | /usr/share/gems/gems/actionpack-6.1.7.10/lib/action_controller/metal/rendering.rb:30:in process_action' c808cf10 | /usr/share/gems/gems/actionpack-6.1.7.10/lib/abstract_controller/callbacks.rb:42:in block in process_action’
c808cf10 | /usr/share/gems/gems/activesupport-6.1.7.10/lib/active_support/callbacks.rb:117:in block in run_callbacks' c808cf10 | /usr/share/foreman/app/controllers/concerns/foreman/controller/timezone.rb:10:in set_timezone’
c808cf10 | /usr/share/gems/gems/activesupport-6.1.7.10/lib/active_support/callbacks.rb:126:in block in run_callbacks' c808cf10 | /usr/share/foreman/app/models/concerns/foreman/thread_session.rb:32:in clear_thread’
c808cf10 | /usr/share/gems/gems/activesupport-6.1.7.10/lib/active_support/callbacks.rb:126:in block in run_callbacks' c808cf10 | /usr/share/foreman/app/controllers/concerns/foreman/controller/topbar_sweeper.rb:12:in set_topbar_sweeper_controller’
c808cf10 | /usr/share/gems/gems/activesupport-6.1.7.10/lib/active_support/callbacks.rb:126:in block in run_callbacks' c808cf10 | /usr/share/gems/gems/audited-5.7.0/lib/audited/sweeper.rb:16:in around’
Example of an another host which was added correctly:
[#<Host::Managed:0x00007f9212af5cc0
id: 15605,
name: "host2-only-for-example",
last_compile: nil,
last_report: nil,
updated_at: Fri, 26 Sep 2025 15:50:17.371656000 UTC +00:00,
created_at: Fri, 26 Sep 2025 15:50:17.371656000 UTC +00:00,
root_pass: nil,
architecture_id: 1,
operatingsystem_id: 3,
ptable_id: nil,
medium_id: nil,
build: false,
comment: "",
disk: nil,
installed_at: nil,
model_id: nil,
hostgroup_id: 2,
owner_id: 5,
owner_type: "User",
enabled: true,
puppet_ca_proxy_id: nil,
managed: false,
use_image: nil,
image_file: nil,
uuid: nil,
compute_resource_id: nil,
puppet_proxy_id: nil,
certname: nil,
image_id: nil,
organization_id: 1,
location_id: 25,
type: "Host::Managed",
otp: nil,
realm_id: nil,
compute_profile_id: nil,
provision_method: nil,
grub_pass: nil,
global_status: 0,
lookup_value_matcher: "[FILTERED]",
pxe_loader: nil,
initiated_at: nil,
build_errors: nil,
creator_id: 5>]
Host which was NOT added correctly:
[#<Host::Base:0x00007f92106e49d0
id: 15582,
name: "host-only-for-an-example",
last_compile: nil,
last_report: nil,
updated_at: Fri, 26 Sep 2025 15:50:09.097348000 UTC +00:00,
created_at: Fri, 26 Sep 2025 15:50:09.097348000 UTC +00:00,
root_pass: nil,
architecture_id: 1,
operatingsystem_id: 3,
ptable_id: nil,
medium_id: nil,
build: false,
comment: "",
disk: nil,
installed_at: nil,
model_id: nil,
hostgroup_id: 1,
owner_id: 5,
owner_type: "User",
enabled: true,
puppet_ca_proxy_id: nil,
managed: false,
use_image: nil,
image_file: nil,
uuid: nil,
compute_resource_id: nil,
puppet_proxy_id: nil,
certname: nil,
image_id: nil,
organization_id: 1,
location_id: 25,
type: nil,
otp: nil,
realm_id: nil,
compute_profile_id: nil,
provision_method: nil,
grub_pass: nil,
global_status: 0,
lookup_value_matcher: "[FILTERED]",
pxe_loader: nil,
initiated_at: nil,
build_errors: nil,
creator_id: 5>]
As you can see the only major difference is the type. But why it’s struggling to set type for a host sometimes? Can someone help me debug ?