Skip to content

aptmirror tasks failing: ItemAdditionError: duplicate key value violates unique constraint "db_collectionitem_unique_active_name"

aptmirror tasks are failing on debusine.debian.net with errors along the lines of the following:

2025-02-03 12:39:55,817 [_task/1536616/139866570408000] ERROR: Exception in Task aptmirror
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "db_collectionitem_unique_active_name"
DETAIL:  Key (name, parent_collection_id)=(0ad-data_0.27.0-1, 3) already exists.


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/debusine/server/collections/debian_suite.py", line 223, in do_add_artifact
    item = CollectionItem.objects.create_from_artifact(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/debusine/db/models/collections.py", line 289, in create_from_artifact
    return CollectionItem.objects.create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/django/db/models/query.py", line 658, in create
    obj.save(force_insert=True, using=self.db)
  File "/usr/lib/python3/dist-packages/debusine/db/models/collections.py", line 603, in save
    super().save(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/django/db/models/base.py", line 814, in save
    self.save_base(
  File "/usr/lib/python3/dist-packages/django/db/models/base.py", line 877, in save_base
    updated = self._save_table(
              ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/django/db/models/base.py", line 1020, in _save_table
    results = self._do_insert(
              ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/django/db/models/base.py", line 1061, in _do_insert
    return manager._insert(
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/django/db/models/query.py", line 1805, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/django/db/models/sql/compiler.py", line 1822, in execute_sql
    cursor.execute(sql, params)
  File "/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 84, in _execute
    with self.db.wrap_database_errors:
  File "/usr/lib/python3/dist-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.IntegrityError: duplicate key value violates unique constraint "db_collectionitem_unique_active_name"
DETAIL:  Key (name, parent_collection_id)=(0ad-data_0.27.0-1, 3) already exists.


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/debusine/tasks/_task.py", line 481, in execute_logging_exceptions
    return self.execute()
           ^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/debusine/server/tasks/base.py", line 67, in execute
    return super().execute()
           ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/debusine/tasks/_task.py", line 494, in execute
    result = self._execute()
             ^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/debusine/server/tasks/aptmirror.py", line 494, in _execute
    self.update_sources(temp_path, self.plan_sources(temp_path))
  File "/usr/lib/python3/dist-packages/debusine/server/tasks/aptmirror.py", line 286, in update_sources
    self.add_source(
  File "/usr/lib/python3/dist-packages/debusine/server/tasks/aptmirror.py", line 267, in add_source
    self.collection_manager.add_source_package(
  File "/usr/lib/python3/dist-packages/debusine/server/collections/debian_suite.py", line 87, in add_source_package
    return self.do_add_artifact(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/debusine/server/collections/debian_suite.py", line 238, in do_add_artifact
    raise ItemAdditionError(str(exc))
debusine.server.collections.base.ItemAdditionError: duplicate key value violates unique constraint "db_collectionitem_unique_active_name"
DETAIL:  Key (name, parent_collection_id)=(0ad-data_0.27.0-1, 3) already exists.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information