Red Hat repository fails to sync (Pulp3Error)

Trying to sync Red Hat repository fails… I’ve tried disabling and re-syncing but I get the same error.

Katello 3.16.1
Pulp Server 2.21.3

Foreman and Proxy plugin versions:
Foreman 2.1.4
Foreman Proxy 2.1.4

Distribution and version:
RHEL 7.9

Katello::Errors::Pulp3Error: duplicate key value violates unique constraint “core_repositoryversion_repository_id_number_3c54ce50_uniq”
DETAIL: Key (repository_id, number)=(412adda7-d6dd-4e52-a278-3dfc735532f0, 1) already exists.

" File “/usr/lib/python3.6/site-packages/rq/”, line 883, in perform_job\n" +
" rv = job.perform()\n" +
" File “/usr/lib/python3.6/site-packages/rq/”, line 645, in perform\n" +
" self._result = self._execute()\n" +
" File “/usr/lib/python3.6/site-packages/rq/”, line 651, in _execute\n" +
" return self.func(*self.args, **self.kwargs)\n" +
" File “/usr/lib/python3.6/site-packages/pulp_rpm/app/tasks/”, line 264, in synchronize\n" +
" dv.create()\n" +
" File “/usr/lib/python3.6/site-packages/pulpcore/plugin/stages/”, line 140, in create\n" +
" with self.repository.new_version() as new_version:\n" +
" File “/usr/lib/python3.6/site-packages/pulp_rpm/app/models/”, line 105, in new_version\n" +
"\n" +
" File “/usr/lib/python3.6/site-packages/django/db/models/”, line 741, in save\n" +
" force_update=force_update, update_fields=update_fields)\n" +
" File “/usr/lib/python3.6/site-packages/django/db/models/”, line 779, in save_base\n" +
" force_update, using, update_fields,\n" +
" File “/usr/lib/python3.6/site-packages/django/db/models/”, line 870, in _save_table\n" +
" result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)\n" +
" File “/usr/lib/python3.6/site-packages/django/db/models/”, line 908, in _do_insert\n" +
" using=using, raw=raw)\n" +
" File “/usr/lib/python3.6/site-packages/django/db/models/”, line 82, in manager_method\n" +
" return getattr(self.get_queryset(), name)(*args, **kwargs)\n" +
" File “/usr/lib/python3.6/site-packages/django/db/models/”, line 1186, in _insert\n" +
" return query.get_compiler(using=using).execute_sql(return_id)\n" +
" File “/usr/lib/python3.6/site-packages/django/db/models/sql/”, line 1375, in execute_sql\n" +
" cursor.execute(sql, params)\n" +
" File “/usr/lib/python3.6/site-packages/django/db/backends/”, line 67, in execute\n" +
" return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)\n" +
" File “/usr/lib/python3.6/site-packages/django/db/backends/”, line 76, in _execute_with_wrappers\n" +
" return executor(sql, params, many, context)\n" +
" File “/usr/lib/python3.6/site-packages/django/db/backends/”, line 84, in _execute\n" +
" return self.cursor.execute(sql, params)\n" +
" File “/usr/lib/python3.6/site-packages/django/db/”, line 89, in exit\n" +
" raise dj_exc_value.with_traceback(traceback) from exc_value\n" +
" File “/usr/lib/python3.6/site-packages/django/db/backends/”, line 84, in _execute\n" +
" return self.cursor.execute(sql, params)\n",
“duplicate key value violates unique constraint “core_repositoryversion_repository_id_number_3c54ce50_uniq”\n” +
“DETAIL: Key (repository_id, number)=(412adda7-d6dd-4e52-a278-3dfc735532f0, 1) already exists.\n”},
“poll_attempts”=>{“total”=>1, “failed”=>1}}

Also same issue when I try to sync “Red Hat Enterprise Linux 6 Server RPMs x86_64 6Server”
Synchronize repository ‘Red Hat Enterprise Linux 6 Server RPMs x86_64 6Server’; product ‘Red Hat Enterprise Linux Server’;

Katello::Errors::Pulp3Error: duplicate key value violates unique constraint “core_repositoryversion_repository_id_number_3c54ce50_uniq”
DETAIL: Key (repository_id, number)=(86be12d0-1509-42cc-a9da-681cc55c0bc0, 2) already exists.

Something I need to fix / delete in Pulp database?

I believe you are running into this issue:

You could either try applying the patch (see or you could try removing the incomplete RepositoryVersions by hand. Here’s the command that works in a Pulp environment (not sure about the manager command in a Katello environment):

pulpcore-manager shell -c "from import RepositoryVersion; RepositoryVersion.objects.filter(complete=False).delete()"
1 Like

If this is a production system, I’d probably advise against running the command. If you do run it, be sure you backup first and stop Katello/Pulp from running.

Justin filed a backport request though so it may even be worth waiting for it:

I believe i just ran into this same error after upgrading from 3.16 to 3.17:

Katello::Errors::Pulp3Error: duplicate key value violates unique constraint "core_repositorycontent_repository_id_content_id_df902e11_uniq"
DETAIL:  Key (repository_id, content_id, version_removed_id)=(5cf832a8-c96a-4336-94f2-1617e2f6f3fa, 0b09dd09-de5e-45a4-9807-61961c29b685, 6f8416a0-8cc2-4a85-b458-5634cad2a6d9) already exists.

I reviewed the github commit and tried to manually apply fix, but got a pulp 503 error, so i rolled back my VM. These are the steps i had done:

Can you elaborate on what you mean by removing conflict by hand with pulpcore-manager? Wasnt sure how to use that command and im not getting fruitful results.