Fixed an issue with copying unsaved Pages (#6420)

pull/6426/head
samgans 2020-10-01 19:14:12 +03:00 zatwierdzone przez GitHub
rodzic e508cbc9c9
commit 7022d0e37a
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 10 dodań i 0 usunięć

Wyświetl plik

@ -1756,6 +1756,10 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase):
:param log_action flag for logging the action. Pass None to skip logging.
Can be passed an action string. Defaults to 'wagtail.copy'
"""
if self._state.adding:
raise RuntimeError('Page.copy() called on an unsaved page')
exclude_fields = self.default_exclude_fields_in_copy + self.exclude_fields_in_copy + (exclude_fields or [])
specific_self = self.specific
if keep_live:

Wyświetl plik

@ -1484,6 +1484,12 @@ class TestCopyPage(TestCase):
# reset excluded fields for future tests
EventPage.exclude_fields_in_copy = []
def test_copy_unsaved_page(self):
"""Test that unsaved page will not be copied."""
new_page = SimplePage(slug='testpurp', title='testpurpose')
with self.assertRaises(RuntimeError):
new_page.copy()
class TestCopyForTranslation(TestCase):
fixtures = ['test.json']