Project

General

Profile

Bug #30322

ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint

Added by Hao Yu about 2 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
Content Views
Target version:
Difficulty:
Triaged:
Yes
Bugzilla link:
Fixed in Releases:
Found in Releases:
Red Hat JIRA:

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

Associated revisions

Revision 93395276 (diff)
Added by Samir Jha almost 2 years ago

Fixes #30322 - Clean orphan content upon repo deletion (#8910)

History

#1 Updated by Hao Yu about 2 years ago

  • Priority changed from Normal to Low

#2 Updated by John Mitsch about 2 years ago

  • Triaged changed from No to Yes
  • Target version set to Katello 4.0.0

#3 Updated by Chris Roberts about 2 years ago

  • Target version changed from Katello 4.0.0 to Katello 3.17.0

#4 Updated by The Foreman Bot almost 2 years ago

  • Assignee set to Samir Jha
  • Status changed from New to Ready For Testing
  • Pull request https://github.com/Katello/katello/pull/8910 added

#5 Updated by The Foreman Bot almost 2 years ago

  • Fixed in Releases Katello 4.0.0 added

#6 Updated by Samir Jha almost 2 years ago

  • Status changed from Ready For Testing to Closed

Also available in: Atom PDF