WeblateOrg / weblate

Web based localization tool with tight version control integration.
https://weblate.org/
GNU General Public License v3.0
4.49k stars 993 forks source link

IntegrityError occurs when deleting a component added from sratch #12293

Open harriebird opened 3 weeks ago

harriebird commented 3 weeks ago

Describe the issue

The IntegrityError occurs when adding an Android String Resource component from scratch and deleting it. The component and is deleted but it will lead to an error page same as shown below:

Screenshot 2024-08-19 at 22-54-41 IntegrityError at _projects_blank-project_

I already tried

Steps to reproduce the behavior

  1. Create a new Project.

  2. In the newly created project, add a new component. In the Create component page, select Start from scratch tab. Provide a Component name, and set its File format to Android String Resource. Click Continue to proceed with the creation of the component.

  3. After a successful creation of the component, the Community localization checklist page is shown. Click Return to the component to go to the Component page. In the Component page, click English in the list of languages.

  4. In the English project language page, you will be a adding new strings via upload since it is blank. To add the new strings, click the Files dropdown and select Upload translation. This will show the Upload form for the translation.

  5. Save the code below as XML file (.xml). This will be uploaded using the Upload form to add new strings.

    <resources>
    <string name="app_name">Github Visualizer</string>
    <string name="my_bio">"A material metaphor is the unifying theory of a rationalized space and a system of motion."</string>
    
    <!-- TODO: Remove or change this placeholder text -->
    <string name="hello_blank_fragment">Hello blank fragment</string>
    <string name="title_activity_profile">ProfileActivity</string>
    <string name="action_settings">Settings</string>
    <string name="title_activity_repository_info" translatable="false">RepositoryInfoActivity</string>
    <string name="title_activity_test_repo">TestRepoActivity</string>
    
    <string name="title_activity_file_viewer">FileViewerActivity</string>
    <string name="dummy_button">Dummy Button</string>
    <string name="dummy_content">DUMMY\nCONTENT</string>
    </resources>
  6. In the Upload form, set the saved XML file as file to be uploaded. Set the File upload mode to Add new strings and click Upload to begin the adding of new strings.

  7. Once the adding of new strings is successful, go back to the Component page for its deletion. In the Component page, click the dropdown Manage and select Organize or remove. Scroll to the bottom part of the page to see the Component removal form. In the Component removal form, provide the full slug of the component to confirm the deletion and click I understand the consequences, delete this translation button to proceed.

  8. After clicking the I understand the consequences, delete this translation button, the IntegrityError page will be shown.

Expected behavior

It is expected that it will redirect to the Project page and display a message The translation component was scheduled for removal. An example screenshot is shown below:

Screenshot 2024-08-19 at 22-55-48 Blank Project @ Devel Weblate

Screenshots

No response

Exception traceback

Internal Server Error: /projects/blank-project/
Traceback (most recent call last):
  File "/app/venv/lib/python3.12/site-packages/weblate/trans/models/component.py", line 1143, in source_translation
    result = self.translation_set.select_related("plural").get(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/db/models/query.py", line 649, in get
    raise self.model.DoesNotExist(
weblate.trans.models.translation.Translation.DoesNotExist: Translation matching query does not exist.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/venv/lib/python3.12/site-packages/django/db/backends/base/base.py", line 299, in _commit
    return self.connection.commit()
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/psycopg/connection.py", line 256, in commit
    self.wait(self._commit_gen())
  File "/app/venv/lib/python3.12/site-packages/psycopg/connection.py", line 394, in wait
    return waiting.wait(gen, self.pgconn.socket, interval=interval)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "psycopg_binary/_psycopg/waiting.pyx", line 213, in psycopg_binary._psycopg.wait_c
  File "/app/venv/lib/python3.12/site-packages/psycopg/_connection_base.py", line 577, in _commit_gen
    yield from self._exec_command(b"COMMIT")
  File "/app/venv/lib/python3.12/site-packages/psycopg/_connection_base.py", line 472, in _exec_command
    raise e.error_from_result(result, encoding=self.pgconn._encoding)
psycopg.errors.ForeignKeyViolation: insert or update on table "trans_translation" violates foreign key constraint "trans_translation_component_id_c4b70a26_fk_trans_component_id"
DETAIL:  Key (component_id)=(39) is not present in table "trans_component".

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

Traceback (most recent call last):
  File "/app/venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/views/decorators/cache.py", line 80, in _view_wrapper
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/weblate/trans/views/basic.py", line 218, in show
    return show_project(request, obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/weblate/trans/views/basic.py", line 413, in show_project
    return render(
           ^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/weblate/trans/util.py", line 247, in render
    return django.shortcuts.render(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/shortcuts.py", line 25, in render
    content = loader.render_to_string(template_name, context, request, using=using)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/loader.py", line 62, in render_to_string
    return template.render(context, request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 171, in render
    return self._render(context)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/loader_tags.py", line 159, in render
    return compiled_parent._render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/loader_tags.py", line 65, in render
    result = block.nodelist.render(context)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/loader_tags.py", line 210, in render
    return template.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 173, in render
    return self._render(context)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/defaulttags.py", line 242, in render
    nodelist.append(node.render_annotated(context))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/defaulttags.py", line 549, in render
    return self.nodelist.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/defaulttags.py", line 326, in render
    return nodelist.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/library.py", line 258, in render
    _dict = self.func(*resolved_args, **resolved_kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/weblate/trans/templatetags/translations.py", line 442, in format_unit_source
    source_translation = unit.translation.component.source_translation
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/utils/functional.py", line 47, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
                                         ^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/weblate/trans/models/component.py", line 1148, in source_translation
    with transaction.atomic():
  File "/app/venv/lib/python3.12/site-packages/django/db/transaction.py", line 263, in __exit__
    connection.commit()
  File "/app/venv/lib/python3.12/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/db/backends/base/base.py", line 323, in commit
    self._commit()
  File "/app/venv/lib/python3.12/site-packages/django/db/backends/base/base.py", line 298, in _commit
    with debug_transaction(self, "COMMIT"), self.wrap_database_errors:
  File "/app/venv/lib/python3.12/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/app/venv/lib/python3.12/site-packages/django/db/backends/base/base.py", line 299, in _commit
    return self.connection.commit()
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/psycopg/connection.py", line 256, in commit
    self.wait(self._commit_gen())
  File "/app/venv/lib/python3.12/site-packages/psycopg/connection.py", line 394, in wait
    return waiting.wait(gen, self.pgconn.socket, interval=interval)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "psycopg_binary/_psycopg/waiting.pyx", line 213, in psycopg_binary._psycopg.wait_c
  File "/app/venv/lib/python3.12/site-packages/psycopg/_connection_base.py", line 577, in _commit_gen
    yield from self._exec_command(b"COMMIT")
  File "/app/venv/lib/python3.12/site-packages/psycopg/_connection_base.py", line 472, in _exec_command
    raise e.error_from_result(result, encoding=self.pgconn._encoding)
django.db.utils.IntegrityError: insert or update on table "trans_translation" violates foreign key constraint "trans_translation_component_id_c4b70a26_fk_trans_component_id"
DETAIL:  Key (component_id)=(39) is not present in table "trans_component".
Internal Server Error: /projects/blank-project/
Traceback (most recent call last):
  File "/app/venv/lib/python3.12/site-packages/weblate/trans/models/component.py", line 1143, in source_translation
    result = self.translation_set.select_related("plural").get(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/db/models/query.py", line 649, in get
    raise self.model.DoesNotExist(
weblate.trans.models.translation.Translation.DoesNotExist: Translation matching query does not exist.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/venv/lib/python3.12/site-packages/django/db/backends/base/base.py", line 299, in _commit
    return self.connection.commit()
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/psycopg/connection.py", line 256, in commit
    self.wait(self._commit_gen())
  File "/app/venv/lib/python3.12/site-packages/psycopg/connection.py", line 394, in wait
    return waiting.wait(gen, self.pgconn.socket, interval=interval)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "psycopg_binary/_psycopg/waiting.pyx", line 213, in psycopg_binary._psycopg.wait_c
  File "/app/venv/lib/python3.12/site-packages/psycopg/_connection_base.py", line 577, in _commit_gen
    yield from self._exec_command(b"COMMIT")
  File "/app/venv/lib/python3.12/site-packages/psycopg/_connection_base.py", line 472, in _exec_command
    raise e.error_from_result(result, encoding=self.pgconn._encoding)
psycopg.errors.ForeignKeyViolation: insert or update on table "trans_translation" violates foreign key constraint "trans_translation_component_id_c4b70a26_fk_trans_component_id"
DETAIL:  Key (component_id)=(39) is not present in table "trans_component".

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

Traceback (most recent call last):
  File "/app/venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/views/decorators/cache.py", line 80, in _view_wrapper
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/weblate/trans/views/basic.py", line 218, in show
    return show_project(request, obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/weblate/trans/views/basic.py", line 413, in show_project
    return render(
           ^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/weblate/trans/util.py", line 247, in render
    return django.shortcuts.render(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/shortcuts.py", line 25, in render
    content = loader.render_to_string(template_name, context, request, using=using)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/loader.py", line 62, in render_to_string
    return template.render(context, request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 171, in render
    return self._render(context)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/loader_tags.py", line 159, in render
    return compiled_parent._render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/loader_tags.py", line 65, in render
    result = block.nodelist.render(context)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/loader_tags.py", line 210, in render
    return template.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 173, in render
    return self._render(context)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/defaulttags.py", line 242, in render
    nodelist.append(node.render_annotated(context))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/defaulttags.py", line 549, in render
    return self.nodelist.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/defaulttags.py", line 326, in render
    return nodelist.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/base.py", line 961, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/template/library.py", line 258, in render
    _dict = self.func(*resolved_args, **resolved_kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/weblate/trans/templatetags/translations.py", line 442, in format_unit_source
    source_translation = unit.translation.component.source_translation
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/utils/functional.py", line 47, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
                                         ^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/weblate/trans/models/component.py", line 1148, in source_translation
    with transaction.atomic():
  File "/app/venv/lib/python3.12/site-packages/django/db/transaction.py", line 263, in __exit__
    connection.commit()
  File "/app/venv/lib/python3.12/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/django/db/backends/base/base.py", line 323, in commit
    self._commit()
  File "/app/venv/lib/python3.12/site-packages/django/db/backends/base/base.py", line 298, in _commit
    with debug_transaction(self, "COMMIT"), self.wrap_database_errors:
  File "/app/venv/lib/python3.12/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/app/venv/lib/python3.12/site-packages/django/db/backends/base/base.py", line 299, in _commit
    return self.connection.commit()
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/psycopg/connection.py", line 256, in commit
    self.wait(self._commit_gen())
  File "/app/venv/lib/python3.12/site-packages/psycopg/connection.py", line 394, in wait
    return waiting.wait(gen, self.pgconn.socket, interval=interval)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "psycopg_binary/_psycopg/waiting.pyx", line 213, in psycopg_binary._psycopg.wait_c
  File "/app/venv/lib/python3.12/site-packages/psycopg/_connection_base.py", line 577, in _commit_gen
    yield from self._exec_command(b"COMMIT")
  File "/app/venv/lib/python3.12/site-packages/psycopg/_connection_base.py", line 472, in _exec_command
    raise e.error_from_result(result, encoding=self.pgconn._encoding)
django.db.utils.IntegrityError: insert or update on table "trans_translation" violates foreign key constraint "trans_translation_component_id_c4b70a26_fk_trans_component_id"
DETAIL:  Key (component_id)=(39) is not present in table "trans_component".
[19/Aug/2024 14:54:00] "GET /projects/blank-project/ HTTP/1.1" 500 493583

How do you run Weblate?

Docker container

Weblate versions

Weblate deploy checks

SystemCheckError: System check identified some issues:

CRITICALS:
?: (weblate.E003) Cannot send e-mail ([Errno 111] Connection refused), please check EMAIL_* settings.
        HINT: https://docs.weblate.org/en/latest/admin/install.html#out-mail
?: (weblate.E012) The server e-mail address should be changed from its default value
        HINT: https://docs.weblate.org/en/latest/admin/install.html#production-email
?: (weblate.E013) The "From" e-mail address should be changed from its default value
        HINT: https://docs.weblate.org/en/latest/admin/install.html#production-email

ERRORS:
?: (weblate.E011) E-mail addresses for site admins is misconfigured
        HINT: https://docs.weblate.org/en/latest/admin/install.html#production-admins

WARNINGS:
?: (security.W004) You have not set a value for the SECURE_HSTS_SECONDS setting. If your entire site is served only over SSL, you may want to consider setting a value and enabling HTTP Strict Transport Security. Be sure to read the documentation first; enabling HSTS carelessly can cause serious, irreversible problems.
?: (security.W008) Your SECURE_SSL_REDIRECT setting is not set to True. Unless your site should be available over both SSL and non-SSL connections, you may want to either set this setting True or configure a load balancer or reverse-proxy server to redirect all connections to HTTPS.
?: (security.W012) SESSION_COOKIE_SECURE is not set to True. Using a secure-only session cookie makes it more difficult for network traffic sniffers to hijack user sessions.
?: (security.W018) You should not have DEBUG set to True in deployment.

INFOS:
?: (weblate.I021) Error collection is not set up, it is highly recommended for production use
        HINT: https://docs.weblate.org/en/latest/admin/install.html#collecting-errors
?: (weblate.I028) Backups are not configured, it is highly recommended for production use
        HINT: https://docs.weblate.org/en/latest/admin/backup.html

System check identified 10 issues (1 silenced).

Additional context

No response

nijel commented 2 weeks ago

This (probably) happens because read-only views do not use transactions so they get mixed view (fetch component which is then removed together with translations). The removal itself happens in a transaction, so it is atomic.

There used to be ATOMIC_REQUESTS turned on, but it was later removed in 041a27c8abc86d6d1dbfe0358d965959d83631d6 as that caused several issues. Also, Django documentation mentions that it doesn't cover template rendering, and that's where we get this issue.

Possible approaches:

I tend to prefer the second approach, as that provides a better user experience, as the object scheduled for removal will disappear immediately from the UI, even if the removal might take long. On the other side, it will need more code changes, but we can initially focus only on the obvious code paths.

harriebird commented 2 weeks ago

Hi @nijel, I have used the second approach as a guide in dealing with this issue. Please check my PR #12345.