ActiveRecord woe

Someone more experienced with this, explain this to me:

[13] pry(#<Foreman::Renderer::Scope::Provisioning>)> ProvisioningTemplate.unscoped.where(name: name)
=> [#<ProvisioningTemplate:0x000055555cf68608
  id: 64,
  name: "kickstart_networking_setup",
  template:
   "<%#\nname: kickstart_networking_setup\nmodel: ProvisioningTemplate\nsnippet: true\nmodel: ProvisioningTemplate\nkind: snippet\n-%>\n<%- bonded_interfaces = [] -%>\n<%- bonding_interfaces = [] -%>\n<%- @host.bond_interfaces.each do |bond| -%>\n<%-   bonding_interfaces.push(bond.identifier) -%>\n<%=   \"# \#{bond.identifier} interface\" %>\n<%=   snippet('kickstart_ifcfg_get_identifier_names', :variables => { :identifier => bond.identifier }) %>\n<%-   ifcfg = snippet('kickstart_ifcfg_bond_interface', :variables => {\n                        :interface => bond,\n                        :subnet => bond.subnet,\n                        :subnet6 => bond.subnet6,\n                        :dhcp => bond.subnet.nil? ? false : bond.subnet.dhcp_boot_mode? }) -%>\n<%=   save_to_file('/etc/sysconfig/network-scripts/ifcfg-$sanitized_real', ifcfg) %>\n\n<%-   @host.interfaces_with_identifier(bond.attached_devices_identifiers).each do |interface| -%>\n<%-     next if !interface.managed? -%>\n<%=     \"# \#{interface.identifier} interface\" %>\n<%=     snippet('kickstart_ifcfg_get_identifier_names', :variables => { :interface => interface }) -%>\n<%-     ifcfg = snippet('kickstart_ifcfg_bonded_interface', :variables => {\n                          :interface => interface,\n                          :subnet => interface.subnet,\n                          :subnet6 => interface.subnet6,\n                          :dhcp => false,\n                          :bond_identifier => bond.identifier }) %>\n<%=     save_to_file('/etc/sysconfig/network-scripts/ifcfg-$sanitized_real', ifcfg) %>\n<%-     bonded_interfaces.push(interface.identifier) %>\n<%-   end -%>\n<%- end -%>\n\n<%- @host.managed_interfaces.each do |interface| %>\n<%-   next if !interface.managed? -%>\n<%-   next if bonded_interfaces.include?(interface.identifier) -%>\n\n<%-   interface_identifier = @host.bond_interfaces.map { |i| i.identifier }.include?(interface.attached_to) ? interface.identifier : nil %>\n<%=   \"# \#{interface.identifier} interface\" %>\n<%=   snippet('kickstart_ifcfg_get_identifier_names', :variables => { :interface => interface, :identifier => interface_identifier }) -%>\n<%-   ifcfg = snippet('kickstart_ifcfg_generic_interface', :variables => {\n                        :interface => interface,\n                        :subnet => interface.subnet,\n                        :subnet6 => interface.subnet6,\n                        :bonding_interfaces => bonding_interfaces,\n                        :dhcp => interface.subnet.nil? ? false : interface.subnet.dhcp_boot_mode?,\n                        :attached_to_bond => interface_identifier.present? }) %>\n<%=   save_to_file('/etc/sysconfig/network-scripts/ifcfg-$sanitized_real', ifcfg) %>\n<%- end %>\n",
  snippet: true,
  template_kind_id: nil,
  created_at: Thu, 01 Jun 2017 12:13:03 CEST +02:00,
  updated_at: Fri, 24 Jan 2020 13:05:32 CET +01:00,
  locked: true,
  default: true,
  vendor: "Foreman",
  type: "ProvisioningTemplate",
  os_family: nil,
  job_category: nil,
  provider_type: nil,
  description_format: nil,
  execution_timeout_interval: nil,
  description: nil>]

[14] pry(#<Foreman::Renderer::Scope::Provisioning>)> ProvisioningTemplate.unscoped.where(name: name, snippet: true)
=> []

What?

Looks like Rails cache is not operating properly:

CACHE ProvisioningTemplate Load (0.0ms)  SELECT "templates".* FROM "templates" WHERE "templates"."type" IN ('ProvisioningTemplate') AND "templates"."name" = ?  [["name", "kickstart_networking_setup"]]

And then

CACHE ProvisioningTemplate Load (0.0ms)  SELECT "templates".* FROM "templates" WHERE "templates"."type" IN ('ProvisioningTemplate') AND "templates"."name" = ? AND "templates"."snippet" = ?  [["name", "kickstart_networking_setup"], ["snippet", 1]]

Uh I do appear to have both “1” and “t” in my sqlite database for column snippet. What’s correct?

sqlite> select snippet from templates;
snippet
f
t
f
0

etc

Well, I have no clue how that happened but this fixed it:

sqlite> update templates set snippet = 1 where snippet = "t";
sqlite> update templates set snippet = 0 where snippet = "f";

Time to move to postgresql on my dev setup I guess.

1 Like

This links to:
https://github.com/theforeman/foreman/pull/7171

1 Like