Bug #30322
closedActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint
Description
Cloned from: https://bugzilla.redhat.com/show_bug.cgi?id=1854026
Description of problem:
Removing the latest content view version doesn't delete the Katello::DockerMetaTag records. This will cause duplicated/orphaned Katello::DockerMetaTag records after publishing a new version. If a tag has both schema v1 manifest and schema v2 manifest then the CV or CCV will fail to publish with the following error:
-------------------------------------
ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_katello_docker_meta_tags_on_schema1_id_and_schema2_id"
DETAIL: Key (schema1_id, schema2_id)=(340545, 340570) already exists.
: INSERT INTO "katello_docker_meta_tags" ("schema1_id", "schema2_id", "name") VALUES ($1, $2, $3) RETURNING "id"
Steps to Reproduce:
1. Create a CCV and add a CV that contains a docker repo.
2. Publish the CCV which will create version 1.
3. Run the following commands to get all orphaned Katello::DockerMetaTag records.
foreman-rake console
Katello::DockerMetaTag.where("id not in (?)", Katello::RepositoryDockerMetaTag.pluck(:docker_meta_tag_id)).size
exit
4. It should return 0 records.
5. Remove the CCV version 1 and wait until the task is finished.
6. Repeat step 3, and you will see some orphaned Katello::DockerMetaTag records.
Additional info:
To fix the "ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint" error, we can run the following commands to remove the orphaned Katello::DockerMetaTag records
NOTE: For security, please make a snapshot of the Satellite before proceeding.
foreman-rake console
Katello::DockerMetaTag.where("id not in (?)", Katello::RepositoryDockerMetaTag.pluck(:docker_meta_tag_id)).delete_all
exit
Updated by John Mitsch over 4 years ago
- Target version set to Katello 4.0.0
- Triaged changed from No to Yes
Updated by Chris Roberts over 4 years ago
- Target version changed from Katello 4.0.0 to Katello 3.17.0
Updated by The Foreman Bot over 4 years ago
- Status changed from New to Ready For Testing
- Assignee set to Samir Jha
- Pull request https://github.com/Katello/katello/pull/8910 added
Updated by The Foreman Bot over 4 years ago
- Fixed in Releases Katello 4.0.0 added
Updated by Samir Jha over 4 years ago
- Status changed from Ready For Testing to Closed
Applied in changeset katello|933952768309480bf742b4369805130bbaa6bf27.