Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async race condition fix - Moved publishing to transaction post-commit #711

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion wagtail_localize/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ def create_or_update_translation(
self.sync_view_restrictions(original, translation)

if publish:
page_revision.publish()
transaction.on_commit(page_revision.publish)

else:
# Note: we don't need to run full_clean for Pages as Wagtail does that in Page.save()
Expand Down
14 changes: 11 additions & 3 deletions wagtail_localize/tests/test_edit_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import tempfile
import uuid

from unittest.mock import patch

import polib

from django.contrib.admin.utils import quote
Expand All @@ -10,6 +12,7 @@
from django.contrib.contenttypes.models import ContentType
from django.contrib.messages import get_messages
from django.core.files.uploadedfile import SimpleUploadedFile
from django.db import transaction
from django.test import TestCase, override_settings
from django.urls import reverse
from django.utils import timezone
Expand Down Expand Up @@ -132,9 +135,10 @@ def setUp(self):
# Create translations
self.fr_locale = Locale.objects.create(language_code="fr")

self.snippet_source, created = TranslationSource.get_or_create_from_instance(
self.snippet
)
(
self.snippet_source,
created,
) = TranslationSource.get_or_create_from_instance(self.snippet)
self.snippet_translation = Translation.objects.create(
source=self.snippet_source,
target_locale=self.fr_locale,
Expand Down Expand Up @@ -168,6 +172,10 @@ def setUp(self):


class TestGetEditTranslationView(EditTranslationTestData, TestCase):
def setUp(self):
with patch.object(transaction, "on_commit", side_effect=lambda func: func()):
super().setUp()

def test_edit_page_translation(self):
response = self.client.get(
reverse("wagtailadmin_pages:edit", args=[self.fr_page.id])
Expand Down
Loading