katello:upgrades:3.0:update_subscription_facet_backend_data aborted

Hi,

I'm facing an error when trying to upgrade from Katello 2.4 to 3.0. The
task katello:upgrades:3.0:update_subscription_facet_backend_data fails
with: ActiveRecord::RecordNotFound: Couldn't find Host::Managed with
'id'=172 [WHERE "hosts"."type" IN ('Host::Managed')]

I have tried to remove the system with foreman-rake console but once I run
again the Katello upgrade task, it will come back again with a new ID:

foreman-rake console
Katello::System.find_by(:host_id=> 172).try(:destroy!)
host = Katello::Host::SubscriptionFacet.find_by(:host_id=> 172).try(:host)
host.subscription_facet.try(:destroy! ) if host
host.content_facet.try(:destroy!) if host

The full error output

[root@mbsbkkkatp01 ~]# foreman-rake
katello:upgrades:3.0:update_subscription_facet_backend_data --trace
** Invoke katello:upgrades:3.0:update_subscription_facet_backend_data
(first_time)
** Invoke environment (first_time)
** Execute environment
** Execute katello:upgrades:3.0:update_subscription_facet_backend_data
Updating backend data for subscription facets
rake aborted!
ActiveRecord::RecordNotFound: Couldn't find Host::Managed with 'id'=172
[WHERE "hosts"."type" IN ('Host::Managed')]
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/relation/finder_methods.rb:320:in
raise_record_not_found_exception!' /opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/relation/finder_methods.rb:420:infind_one'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/relation/finder_methods.rb:404:in
find_with_ids' /opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/relation/finder_methods.rb:68:infind'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/querying.rb:3:in
find&#39; /opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.0.2/lib/katello/tasks/upgrades/3.0/update_subscription_facet_backend_data.rake:13:inblock (5 levels) in <top (required)>'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/relation/batches.rb:52:in
block (2 levels) in find_each&#39; /opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/relation/batches.rb:52:ineach'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/relation/batches.rb:52:in
block in find_each&#39; /opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/relation/batches.rb:125:infind_in_batches'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/relation/batches.rb:51:in
find_each&#39; /opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/querying.rb:9:infind_each'
/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.0.2/lib/katello/tasks/upgrades/3.0/update_subscription_facet_backend_data.rake:8:in
block (4 levels) in &lt;top (required)&gt;&#39; /opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:240:incall'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:240:in
block in execute&#39; /opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:235:ineach'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:235:in
execute&#39; /opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:179:inblock in invoke_with_call_chain'
/opt/rh/rh-ruby22/root/usr/share/ruby/monitor.rb:211:in mon_synchronize&#39; /opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:172:ininvoke_with_call_chain'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:165:in
invoke&#39; /opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:150:ininvoke_task'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:106:in
block (2 levels) in top_level&#39; /opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:106:ineach'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:106:in
block in top_level&#39; /opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:115:inrun_with_threads'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:100:in
top_level&#39; /opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:78:inblock in run'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:176:in
standard_exception_handling&#39; /opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:75:inrun'
/opt/rh/rh-ruby22/root/usr/bin/rake:33:in `<main>'
Tasks: TOP => katello:upgrades:3.0:update_subscription_facet_backend_data

I don't mind to remove all the subscriptions and assign again after as part
of the solution.

What can I do?

Best Regards,

Joaquin