duplicate key value violates unique constraint "core_personpreferencemodel_section_name_5beac7ca_uniq"
Steps to reproduce (tested with Core 4.0.0.dev3)
- Create at least two persons and enter dates of birth
- Try to view calender with birthdays enabled
Either I don't understand how PersonPreferenceModel
is supposed to work, or the unique contstraint (section, name) is just wrong.
AFAIU the constraint should be (section, name, instance).
Error message:
2024-01-29 13:40:30,109 ERROR django.request[14341]: Internal Server Error: /graphql/
Traceback (most recent call last):
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/dynamic_preferences/managers.py", line 155, in get_db_pref
pref = self.queryset.get(section=section, name=name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/models/query.py", line 637, in get
raise self.model.DoesNotExist(
aleksis.core.models.PersonPreferenceModel.DoesNotExist: PersonPreferenceModel matching query does not exist.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/models/query.py", line 916, in get_or_create
return self.get(**kwargs), False
^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/models/query.py", line 637, in get
raise self.model.DoesNotExist(
aleksis.core.models.PersonPreferenceModel.DoesNotExist: PersonPreferenceModel matching query does not exist.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django_prometheus/db/common.py", line 69, in execute
return super().execute(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "core_personpreferencemodel_section_name_5beac7ca_uniq"
DETAIL: Key (section, name)=(notification, addressing_name_format) already exists.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/views/decorators/csrf.py", line 56, in wrapper_view
return view_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/views/generic/base.py", line 104, in view
return self.dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/utils/decorators.py", line 46, in _wrapper
return bound_method(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/utils/decorators.py", line 134, in _wrapper_view
response = view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/graphene_django/views.py", line 178, in dispatch
responses = [self.get_response(request, entry) for entry in data]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/graphene_django/views.py", line 178, in <listcomp>
responses = [self.get_response(request, entry) for entry in data]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/graphene_django/views.py", line 205, in get_response
execution_result = self.execute_graphql_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/src/aleksis/apps/official/AlekSIS-Core/aleksis/core/views.py", line 1466, in execute_graphql_request
raise error
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/graphql/execution/execute.py", line 540, in execute_field
completed = self.complete_value(
^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/graphql/execution/execute.py", line 607, in complete_value
raise result
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/graphene_django/debug/middleware.py", line 65, in resolve
result = next(root, info, **args)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/src/aleksis/apps/official/AlekSIS-Core/aleksis/core/schema/calendar.py", line 71, in resolve_events
feed = root.create_feed(info.context, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/src/aleksis/apps/official/AlekSIS-Core/aleksis/core/mixins.py", line 654, in create_feed
cls.create_event(reference_object, feed, request=request, params=params)
File "/home/felix/src/aleksis/apps/official/AlekSIS-Core/aleksis/core/mixins.py", line 617, in create_event
field_value = cls.get_event_field_value(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/src/aleksis/apps/official/AlekSIS-Core/aleksis/core/mixins.py", line 695, in get_event_field_value
return getattr(cls, method_name)(reference_object, request=request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/src/aleksis/apps/official/AlekSIS-Core/aleksis/core/models.py", line 1597, in value_title
return _("{}'s birthday").format(reference_object.addressing_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/src/aleksis/apps/official/AlekSIS-Core/aleksis/core/models.py", line 282, in addressing_name
if self.preferences["notification__addressing_name_format"] == "last_first":
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/dynamic_preferences/managers.py", line 34, in __getitem__
return self.get(key)
^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/dynamic_preferences/managers.py", line 149, in get
db_pref = self.get_db_pref(section=section, name=name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/dynamic_preferences/managers.py", line 158, in get_db_pref
pref = self.create_db_pref(
^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/dynamic_preferences/managers.py", line 196, in create_db_pref
db_pref, created = self.model.objects.get_or_create(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/models/query.py", line 923, in get_or_create
return self.create(**params), True
^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/models/query.py", line 658, in create
obj.save(force_insert=True, using=self.db)
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/dynamic_preferences/models.py", line 77, in save
super(BasePreferenceModel, self).save(**kwargs)
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/models/base.py", line 814, in save
self.save_base(
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/models/base.py", line 877, in save_base
updated = self._save_table(
^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/models/base.py", line 1020, in _save_table
results = self._do_insert(
^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/models/base.py", line 1061, in _do_insert
return manager._insert(
^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/models/query.py", line 1805, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/cachalot/monkey_patch.py", line 37, in inner
return original(compiler, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/cachalot/monkey_patch.py", line 113, in inner
return original(write_compiler, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1822, in execute_sql
cursor.execute(sql, params)
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/graphene_django/debug/sql/tracking.py", line 153, in execute
return self._record(self.cursor.execute, sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/graphene_django/debug/sql/tracking.py", line 99, in _record
return method(sql, params)
^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/backends/utils.py", line 102, in execute
return super().execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/cachalot/monkey_patch.py", line 137, in inner
return original(cursor, sql, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/backends/utils.py", line 84, in _execute
with self.db.wrap_database_errors:
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/felix/.cache/pypoetry/virtualenvs/aleksis-core-VLqlbO2E-py3.11/lib/python3.11/site-packages/django_prometheus/db/common.py", line 69, in execute
return super().execute(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
graphql.error.graphql_error.GraphQLError: duplicate key value violates unique constraint "core_personpreferencemodel_section_name_5beac7ca_uniq"
DETAIL: Key (section, name)=(notification, addressing_name_format) already exists.
GraphQL request:10:7
9 | activated
10 | events(start: $start, end: $end, params: $params) {
| ^
11 | name