[Satellite6] katello:correct_repositories rake script raises PG::UniqueViolation when creating missing pulp repo for custom product
Environment
Red Hat Satellite 6.6+
Issue
Running foreman-rake katello:correct_repositories script fails with PG::UniqueViolation error when attempting to fix a custom repository.
Resolution
For a final resolution, wait until This content is not included.the underlying bug is fixed.
As a workaround, temporarily comment out one line of code that is ridiculous for the rake script purposes:
- Edit
/opt/theforeman/tfm/root/usr/share/gems/gems/katello-<your version>/app/lib/actions/katello/product/content_create.rband comment out the line 55 like:
# ::Katello::ProductContent.create!(product: root.product, content: content, enabled: true)
- Apply the change:
touch ~foreman/tmp/restart.txt
-
Wait a minute or two to let re-spawn the change.
-
Run the rake script - it should succeed now.
-
Revert the change by uncomment the line 55 of the modified file.
-
Apply the revert:
touch ~foreman/tmp/restart.txt
For more KB articles/solutions related to Red Hat Satellite 6.x Repository Issues, please refer to the Red Hat Satellite Consolidated Troubleshooting Article for Red Hat Satellite 6.x Repository Issues.
For more KB articles/solutions related to Red Hat Satellite 6.x Pulp 2.0 Issues, please refer to the Consolidated Troubleshooting Article for Red Hat Satellite 6.x Pulp 2.0-related Issues
Root Cause
See the reasoning in This content is not included.the bugzilla.
Diagnostic Steps
foreman-rake katello:correct_repositories COMMIT=true
..
Processing Repository 1007/2015: my_custom_repo_007 (1007)
Repository 1007 Missing
Recreating 1007
rake aborted!
ForemanTasks::TaskError: Task 4eb47622-b266-4f59-b11e-12df6c40c57b: ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "katello_contents_cpcid_orgid_uniq"
DETAIL: Key (cp_content_id, organization_id)=(1578403469831, 1) already exists.
: INSERT INTO "katello_contents" ("cp_content_id", "content_type", "name", "label", "vendor", "content_url", "organization_id") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id"
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-0.15.11.1/lib/foreman_tasks.rb:59:in `block in sync_task'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-0.15.11.1/lib/foreman_tasks.rb:58:in `tap'
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-0.15.11.1/lib/foreman_tasks.rb:58:in `sync_task'
/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.12.0.29/lib/katello/tasks/repository.rake:149:in `handle_missing_repo'
/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.12.0.29/lib/katello/tasks/repository.rake:66:in `block (3 levels) in <top (required)>'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/relation/batches.rb:70:in `block (2 levels) in find_each'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/relation/batches.rb:70:in `each'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/relation/batches.rb:70:in `block in find_each'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/relation/batches.rb:136:in `block in find_in_batches'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/relation/batches.rb:238:in `block in in_batches'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/relation/batches.rb:222:in `loop'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/relation/batches.rb:222:in `in_batches'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/relation/batches.rb:135:in `find_in_batches'
/opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/relation/batches.rb:69:in `find_each'
/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.12.0.29/lib/katello/tasks/repository.rake:63:in `with_index'
/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.12.0.29/lib/katello/tasks/repository.rake:63:in `block (2 levels) in <top (required)>'
/opt/rh/rh-ruby25/root/usr/share/gems/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => katello:correct_repositories
(See full trace by running task with --trace)
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.