Skip to content

Commit

Permalink
Prevent error on page editing after changing LANGUAGE_CODE
Browse files Browse the repository at this point in the history
Fixes #6860 as per #6860 (comment).
  • Loading branch information
gasman committed Mar 5, 2021
1 parent 6e20cec commit 4344d82
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
52 changes: 52 additions & 0 deletions wagtail/admin/tests/pages/test_edit_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,58 @@ def test_post_edit_alias_page(self):

self.assertEqual(response.status_code, 405)

def test_edit_after_change_language_code(self):
"""
Verify that changing LANGUAGE_CODE with no corresponding database change does not break editing
"""
# Add a draft revision
self.child_page.title = "Hello world updated"
self.child_page.save_revision()

# Hack the Locale model to simulate a page tree that was created with LANGUAGE_CODE = 'de'
# (which is not a valid content language under the current configuration)
Locale.objects.update(language_code='de')

# Tests that the edit page loads
response = self.client.get(reverse('wagtailadmin_pages:edit', args=(self.child_page.id, )))
self.assertEqual(response.status_code, 200)

# Tests simple editing
post_data = {
'title': "I've been edited!",
'content': "Some content",
'slug': 'hello-world',
}
response = self.client.post(reverse('wagtailadmin_pages:edit', args=(self.child_page.id, )), post_data)

# Should be redirected to edit page
self.assertRedirects(response, reverse('wagtailadmin_pages:edit', args=(self.child_page.id, )))

def test_edit_after_change_language_code_without_revisions(self):
"""
Verify that changing LANGUAGE_CODE with no corresponding database change does not break editing
"""
# Hack the Locale model to simulate a page tree that was created with LANGUAGE_CODE = 'de'
# (which is not a valid content language under the current configuration)
Locale.objects.update(language_code='de')

PageRevision.objects.filter(page_id=self.child_page.id).delete()

# Tests that the edit page loads
response = self.client.get(reverse('wagtailadmin_pages:edit', args=(self.child_page.id, )))
self.assertEqual(response.status_code, 200)

# Tests simple editing
post_data = {
'title': "I've been edited!",
'content': "Some content",
'slug': 'hello-world',
}
response = self.client.post(reverse('wagtailadmin_pages:edit', args=(self.child_page.id, )), post_data)

# Should be redirected to edit page
self.assertRedirects(response, reverse('wagtailadmin_pages:edit', args=(self.child_page.id, )))


class TestPageEditReordering(TestCase, WagtailTestUtils):
def setUp(self):
Expand Down
4 changes: 0 additions & 4 deletions wagtail/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,6 @@ def pk(obj):


class LocaleManager(models.Manager):
def get_queryset(self):
# Exclude any locales that have an invalid language code
return super().get_queryset().filter(language_code__in=get_content_languages().keys())

def get_for_language(self, language_code):
"""
Gets a Locale from a language code.
Expand Down

0 comments on commit 4344d82

Please sign in to comment.