Skip to content

psycopg.errors.UniqueViolation: duplicate key value violates unique constraint "pagetranslation_unique_version" when saving a translation #4073

@MizukiTemma

Description

@MizukiTemma

Describe the Bug

Sometimes this error occurs when saving a content. It has been observed lately more often. Service Team could not use Bulk MT due to this error.

This bug does not occur always. Trigger conditions are unclear.

However, there is a tendency in bulk MT: it seems not to be (completely) random. Looks like, once a page faces this error, it keeps suffering from it, regardless of which language is chosen for a bulk MT next time.

Interesting was that MT worked fine as only this suffering page alone is selected for a bulk MT action or it is trasnlated into multiple languages on the page form (by translation side box).

Steps to Reproduce

---- What I observed

  1. Go to a location (A)
  2. Change something
  3. Save it
  4. Repeat this relatively repidly
  5. Face the error
  6. Return to the locations list, open the location (A)
  7. Change something and save
  8. See the error again

---- What Service Team experienced --------------

  1. Go to the page tree
  2. Select pages (including one or more "suffering" page(s))
  3. Use bulk MT
  4. See the error

Expected Behavior

No error, MT is not blocked

Actual Behavior

Error, MT blocked

Screenshot

Additional Information

Traceback
`Dec 15 07:45:54 ERROR   django.request - 500 Internal Server Error: /kaufbeuren/pages/hr/machine-translate/
Traceback (most recent call last):
  File "/opt/integreat-cms/.venv/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/integreat-cms/.venv/lib/python3.11/site-packages/psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)
psycopg.errors.UniqueViolation: duplicate key value violates unique constraint "pagetranslation_unique_version"
DETAIL:  Key (page_id, language_id, version)=(9507, 22, 4) already exists.

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

Traceback (most recent call last):
  File "/opt/integreat-cms/.venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/integreat-cms/.venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, callback_args, callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/integreat-cms/.venv/lib/python3.11/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/integreat-cms/.venv/lib/python3.11/site-packages/django/contrib/auth/mixins.py", line 109, in dispatch
    return super().dispatch(request, args, *kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/integreat-cms/.venv/lib/python3.11/site-packages/django/views/generic/base.py", line 143, in dispatch
    return handler(request, args, *kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/integreat-cms/.venv/lib/python3.11/site-packages/integreat_cms/cms/views/bulk_action_views.py", line 226, in post
    api_client.translate_queryset(to_translate, language_node.slug)
  File "/usr/lib/python3.11/contextlib.py", line 81, in inner
    return func(args, kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/integreat-cms/.venv/lib/python3.11/site-packages/integreat_cms/core/utils/machine_translation_api_client.py", line 161, in translate_queryset
    self.invoke_translation_api()
  File "/opt/integreat-cms/.venv/lib/python3.11/site-packages/integreat_cms/google_translate_api/google_translate_api_client.py", line 130, in invoke_translation_api
    self.save_translation(content_object, data)
  File "/opt/integreat-cms/.venv/lib/python3.11/site-packages/integreat_cms/core/utils/machine_translation_api_client.py", line 321, in save_translation
    content_translation_form.save()
  File "/opt/integreat-cms/.venv/lib/python3.11/site-packages/integreat_cms/cms/forms/machine_translation_form.py", line 151, in save
    self.instance = super().save(commit, foreign_form_changed)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/integreat-cms/.venv/lib/python3.11/site-packages/integreat_cms/cms/forms/custom_content_model_form.py", line 143, in save
    result = super().save(commit=commit)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/integreat-cms/.venv/lib/python3.11/site-packages/integreat_cms/cms/forms/custom_model_form.py", line 133, in save
    return super().save(commit=commit)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/integreat-cms/.venv/lib/python3.11/site-packages/django/forms/models.py", line 542, in save
    self.instance.save()
  File "/opt/integreat-cms/.venv/lib/python3.11/site-packages/integreat_cms/cms/models/pages/page_translation.py", line 435, in save
    super().save(*args, kwargs)
  File "/opt/integreat-cms/.venv/lib/python3.11/site-packages/integreat_cms/cms/models/abstract_content_translation.py", line 668, in save
    super().save(args, *kwargs)
  File "/opt/integreat-cms/.venv/lib/python3.11/site-packages/django/db/models/base.py", line 814, in save
    self.save_b  [truncated from 6726 characters]`

Related Issues

Summary of discussion and updates to the description

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions