Bug 1585408 - SQL error when adding some puppet modules to CV: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "katello_cv_puppet_modules_name"
Summary: SQL error when adding some puppet modules to CV: PG::UniqueViolation: ERROR: ...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Content Views
Version: 6.4
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: 6.4.0
Assignee: Stephen Benjamin
QA Contact: Lai
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-06-02 13:37 UTC by Jan Hutař
Modified: 2019-11-05 23:22 UTC (History)
10 users (show)

Fixed In Version: tfm-rubygem-katello-3.7.0.rc1.2-0.1.rc1.2
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-10-16 19:08:39 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 23945 0 Normal Closed SQL error when adding some puppet modules to CV: PG::UniqueViolation: ERROR: duplicate key value violates unique constr... 2020-07-09 01:45:09 UTC

Description Jan Hutař 2018-06-02 13:37:35 UTC
Description of problem:
SQL error when adding some puppet modules to CV: PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "katello_cv_puppet_modules_name"


Version-Release number of selected component (if applicable):
satellite-6.4.0-9.beta.el7sat.noarch
tfm-rubygem-hammer_cli-0.13.0-1.el7sat.noarch


How reproducible:
happens for about 20% of modules


Steps to Reproduce:
1. Sync whole PuppetForge, create content view "MyCV"
2. # hammer --csv -u admin -p changeme puppet-module list \
         > puppet-module-list.csv
3. # for u in $( cut -d ',' -f 5 puppet-module-list.csv  ); do
         hammer -u admin -p changeme content-view puppet-module add \
             --content-view "MyCV" --organization "Default Organization" \
             --uuid "$u"
     done


Actual results:
Could not add the puppet module:
  PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "katello_cv_puppet_modules_name"
  DETAIL:  Key (name, content_view_id)=(sumo, 7) already exists.
  : INSERT INTO "katello_content_view_puppet_modules" ("content_view_id", "name", "author", "uuid", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id"


Expected results:
Either should work or should provide some user friendly message

Comment 1 Marek Hulan 2018-06-04 07:13:04 UTC
This feels more like server issue (database error is probably not related to CLI), moving to content views as the foreign key is probably added from there.

Comment 3 Stephen Benjamin 2018-06-14 17:09:14 UTC
Created redmine issue http://projects.theforeman.org/issues/23945 from this bug

Comment 4 Stephen Benjamin 2018-06-14 17:17:42 UTC
Many people can, for example, create a "motd" module. They are namespaced by author, so while "puppetlabs/motd" and "stbenjam/motd" are different modules, clients just reference 'motd' meaning they can only have 1 of that name available.  In Katello, a repo can have many implementations of 'motd' but a content view can only have 1.

A better reproducer than syncing all of puppet forge:


1. Create a puppet module repository
2. Upload the [puppetlabs](https://forge.puppet.com/v3/files/puppetlabs-motd-1.9.0.tar.gz) and [ericsson](https://forge.puppet.com/v3/files/ericsson-motd-1.0.3.tar.gz) implementations of 'motd', and get the UUID's with `hammer puppet-module list`:

```
3  | motd  | ericsson   | 1.0.3   | 7ade8518-4314-49e9-a7ab-b6ed5cf2df59l
2  | motd  | puppetlabs | 1.9.0   | 45b9a9a2-2a9e-48b1-8a2d-160ae0fec59c
```

3. Create a content-view and try adding both modules:


```
$ hammer content-view puppet-module add --content-view-id 2 --organization-id=1 --uuid 7ade8518-4314-49e9-a7ab-b6ed5cf2df59
Puppet module added to content view
$ hammer content-view puppet-module add --content-view-id 2 --organization-id=1 --uuid 45b9a9a2-2a9e-48b1-8a2d-160ae0fec59c
```

Previously you'd get this error:

```
Could not add the puppet module:
  PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "katello_cv_puppet_modules_name"
  DETAIL:  Key (name, content_view_id)=(motd, 2) already exists.
  : INSERT INTO "katello_content_view_puppet_modules" ("content_view_id", "name", "author", "uuid", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id"
```

With this change, you'll get the more user friendly:


```
There is already a module named "motd" in this content view.
```

Comment 5 Satellite Program 2018-06-14 18:24:38 UTC
Upstream bug assigned to stbenjam

Comment 6 Satellite Program 2018-06-14 18:24:43 UTC
Upstream bug assigned to stbenjam

Comment 7 Satellite Program 2018-06-15 16:24:25 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue http://projects.theforeman.org/issues/23945 has been resolved.

Comment 8 Lai 2018-09-17 19:39:34 UTC
1) Create a puppet module repository
2) Upload the [puppetlabs](https://forge.puppet.com/v3/files/puppetlabs-motd-1.9.0.tar.gz) and [ericsson](https://forge.puppet.com/v3/files/ericsson-motd-1.0.3.tar.gz) implementations of 'motd', and get the UUID's with `hammer puppet-module list`:

3)
---|------|------------|---------|-------------------------------------
ID | NAME | AUTHOR     | VERSION | UUID                                
---|------|------------|---------|-------------------------------------
2  | motd | ericsson   | 1.0.3   | 5d3b1bca-0138-4392-a7cf-c71c68eae748
1  | motd | puppetlabs | 1.9.0   | 555698ac-8ad3-47b0-8761-5b59161007c9
---|------|------------|---------|-------------------------------------

4) # hammer content-view puppet-module add --content-view-id 3 --organization-id=1 --uuid 5d3b1bca-0138-4392-a7cf-c71c68eae748
Puppet module added to content view

5) # hammer content-view puppet-module add --content-view-id 3 --organization-id=1 --uuid 555698ac-8ad3-47b0-8761-5b59161007c9

Validation failed: Name There is already a module named "motd" in this content view.

User friendly message was able to be generated with the above steps in sat6.4.

This was verified in snap_6.4.0_22.0.

Comment 9 Bryan Kearney 2018-10-16 19:08:39 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2018:2927


Note You need to log in before you can comment on or make changes to this bug.