Bug #23942
closedError deleting manifest. PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_katello_pools_on_cp_id"
Description
Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1581700
Description of problem: Trying to delete manifest after upgrade to satellite 6.4 snap 4 from satellite 6.3.1, gives error Error deleting manifest. PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_katello_pools_on_cp_id" DETAIL: Key (cp_id)=(8a88f7815e22b340015e22bc74ea0196) already exists. : INSERT INTO "katello_pools" ("cp_id", "created_at", "updated_at", "organization_id") VALUES ($1, $2, $3, $4) RETURNING "id"
Version-Release number of selected component (if applicable): Satellite 6.4
How reproducible: always
Steps to Reproduce:
1. Upgrade satellite to 6.4 snap 4
2. Upload manifest
3. Try to delete manifest
Actual results:
Error deleting manifest. PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_katello_pools_on_cp_id"
and production.log showed
2018-05-23T08:25:31 [W|app|f29fc] Orphaned Product id 883 found while refreshing/importing manifest.
2018-05-23T08:25:31 [W|app|f29fc] Orphaned Product id 882 found while refreshing/importing manifest.
2018-05-23T08:25:31 [W|app|f29fc] Orphaned Product id 881 found while refreshing/importing manifest.
2018-05-23T08:25:31 [W|app|f29fc] Orphaned Product id 880 found while refreshing/importing manifest.
2018-05-23T08:25:31 [W|app|f29fc] Orphaned Product id 879 found while refreshing/importing manifest.
2018-05-23T08:25:31 [W|app|f29fc] Orphaned Product id 878 found while refreshing/importing manifest.
2018-05-23T08:25:34 [I|aud|] update event for Organization with id 36
2018-05-23T08:30:15 [E|bac|] PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_katello_pools_on_cp_id"
DETAIL: Key (cp_id)=(8a88f7815e22b340015e22bc74ea0196) already exists.
: INSERT INTO "katello_pools" ("cp_id", "created_at", "updated_at", "organization_id") VALUES ($1, $2, $3, $4) RETURNING "id" (ActiveRecord::RecordNotUnique)
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:614:in `async_exec'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:614:in `block (2 levels) in exec_no_cache'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:46:in `block in permit_concurrent_loads'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/concurrency/share_lock.rb:185:in `yield_shares'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:45:in `permit_concurrent_loads'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:613:in `block in exec_no_cache'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:612:in `block (2 levels) in log'
/opt/rh/rh-ruby24/root/usr/share/ruby/monitor.rb:214:in `mon_synchronize'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:611:in `block in log'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:603:in `log'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:612:in `exec_no_cache'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:601:in `execute_and_clear'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:79:in `exec_query'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:102:in `exec_insert'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:113:in `exec_insert'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:133:in `insert'
Expected results: Manifest delete success.
Additional info: